10

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 ?

Community
  • 1
  • 1
ziritrion
  • 319
  • 2
  • 8
  • 17

3 Answers3

9

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.

ZachM
  • 893
  • 2
  • 8
  • 22
Yury
  • 20,618
  • 7
  • 58
  • 86
  • Yeah, I used the Android.mk found in the gdbserver in the same directory for reference, but it wasn't working for some readon. I'm gonna try with mmmm; I'll be right back... EDIT: *mmm prebuilt snod -j* worked! I'm going to do a *make clean* and see if rebuilding everything from scratch works as well... – ziritrion Jun 13 '12 at 14:50
  • Something really weird is going on... Running *make* on the source code straight from repo (without my binary) compiles fine. But when I add my binary, I get weird errors. The worst thing is that even if I do a *make clean* and take out my folder (which should let the source code just as it was at the beginning since I'm not touching anything else), when I try to compile it I'll still get compiling errors. I'm freeing space nad making sure it's not anything not related to the code itself (I'm running Ubuntu 10.04 on VMware) – ziritrion Jun 13 '12 at 19:15
  • make clean simply delete 'out' folder. It does not change code to defaoult. Can you update your answer with the errors that you get during the compilation? – Yury Jun 13 '12 at 21:09
  • Nevermind... I re-downloaded the source from repo and built it without ccache and using plain *make*, wihtout any -j4, and it just built. Anyway, it's still not working; my binary doesn't appear in /system/bin when using DDMS on the emulator. – ziritrion Jun 14 '12 at 12:41
  • It's strange. I see this file in my emulator - I've just checked. – Yury Jun 20 '12 at 21:24
4

if your binary ends up in the out directory but not in the image, it's because you don't have a rule to include the binary in the image.

in device/<vendorname>/<devicename>/device.mk (or in some makefile included by device.mk) you need to have one of two entries:

PRODUCT_PACKAGES += my-binary

or:

PRODUCT_COPY_FILES += path/to/my-binary:/root/target/path/to/my-binary

... I would suggest the PRODUCT_PACKAGES approach; PRODUCT_COPY_FILES is better suited to scripts and configuration files.

NOTE: PRODUCT_PACKAGES uses the module name, where PRODUCT_COPY_FILES uses the actual name/location of the binary.

Ch4ni
  • 292
  • 1
  • 10
0

You can also the following which works for me ..... LOCAL_MDULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) ... include $(BUILD_EXECUTABLE)

Bill Chan
  • 61
  • 1
  • 3