Search code examples
androidandroid-sourceandroid-build

Create a symlink building an Android image


I'm writing the definition of a new device and product to build a custom Android image and I need to create a symbolic link while building the image, but it's not clear what's the correct way to do it in an Android mk file.

As an example, let's say that I need to create a link named wget that points to the executable busybox in the /system/bin directory.

Using a call to a shell command like the following may work, but it's heavily discouraged since it's executed multiple times, when the mk file is parsed (and so is applied also on the host system):

$(shell ln -frs $(TARGET_OUT_EXECUTABLES)/busybox $(TARGET_OUT_EXECUTABLES)/wget)

Another approach that I tried was to populate a directory tree like this:

$ tree device/my_vendor/my_device/links
links
└── system
    └── bin
        └── wget -> busybox

and then use this code:

PRODUCT_COPY_FILES += \
        $(call find-copy-subdir-files,*,device/my_vendor/my_device/links,$(TARGET_COPY_OUT_ROOT))

but no file at all is created in the image, and there is nothing in the logs.

So, what's the correct way to add a symlink, creating an Android image?

Bonus question: how to create a link that will reside in the root? Something like /link pointing to /vendor/directory, for example?

Thanks!


Solution

  • Use LOCAL_POST_INSTALL_CMD (for all type modules) or LOCAL_POST_LINK_CMD (only for executable)

    1. LOCAL_POST_INSTALL_CMD example
    2. LOCAL_POST_LINK_CMD example