androidandroid-sourceandroid-make

Replacing some files before packaging system folder to system.img


As the title is self-explanatory, I'd want to replace some files in system/bin/ and system/lib/ right before when the system.img is being generated.

To be more exact, I've got some prebuilt .so files which shuold be copied over the existing ones. For example libart.so. Please note that replacing art/ (source code of art) with the modified art source code is not an option.

To do this, which mk file should I investigate and put my replacing code into?


Solution

  • You may follow the same structure as the one proposed in this other question, but use this macro:

    PRODUCT_COPY_FILES += \
         device/common/my_bin.bin:cache/my_bin.bin \
         device/common/my_so.so:system/art/my_so.so
    

    This works as follows:

    Also, the order in which this files are copied, matters. For instance if you are copying a file that already exists, hence, you want it replaced. (As your libart.so), you would need YOUR call to that copy to be done before the default one.

    For this, I recommend doing:

    It's not easy to answer where to add it. I have never modified libart.so myself, but I have copied many files this way and it works like a charm.

    I hope it works for your case as well.