Adding a prebuilt binary in Android source

ziritrion picture ziritrion · Jun 13, 2012 · Viewed 14.8k times · Source

I have a native binary that I want to include into Android's source code, so that when I compile it my binary will be included in /system/bin .

I've copied my binary into the folder /prebuilt/android-arm/my-binary , and I've created a new Android.mk with the following:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES := my-binary
LOCAL_MODULE := my-binary
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_MODULE_TAGS := optional
include $(BUILD_PREBUILT)

But when I run make, the only reference I get in the log is the following:

target Prebuilt: my-binary (out/target/product/generic/obj/EXECUTABLES/my-binary_intermediates/my-binary)

And the binary isn't installed into system.img at all. There's an almost identical question in Installing a prebuilt binary on Android: "not found" , but the asker already knew the basic procedure and it isn't explained at all. If I run make my-binary, I get the same line I posted.

I've also tried to run make out/target/product/generic/system.img my-binary but it doesn't work either. My binary shows up in the the out subfolder but it won't be included into system.imng

Am I missing something? Is there any way so that with just running make -j# my binary will be included in /system/bin ?

Answer

Yury picture Yury · Jun 13, 2012

Just tested on my emulator and it's working. I used as an example gdbserver in this folder. I have a strace crosscompiled for android and use it to be embedded into the image. So, the instructions will be for this executable.

  1. Create a folder under prebuilt/android-arm/strace
  2. Put there your binary (in my case strace)

Add Android.mk file with the following content:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES := strace
LOCAL_MODULE := strace
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_MODULE_TAGS := optional
include $(BUILD_PREBUILT)


prebuilt_files :=

$(call add-prebuilt-files, EXECUTABLES, $(prebuilt_files))

Build with the instruction: mmm prebuilt snod -j4 (if you have images already built) or you, of course, can use make -j4 as well.