0

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?

frogatto
  • 28,539
  • 11
  • 83
  • 129

3 Answers3

3

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:

  • The file is copied from left to(:) right.
  • When the image is generated, in this case cache or system, it would be generated with the files contained in those folders.
  • As we have copied our files to that destination, when system.img is generated, our file will be contained.

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:

  • source build/envsetup.sh
  • lunch <<device>>
  • mgrep libart.so -> This does a grep through mk files, so you can see where the default copy is done.
  • Insert $(info whatever) calls in desired mk files to trace where is a good spot to add your PRODUCT_COPY_FILES.

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.

Olaia
  • 2,172
  • 25
  • 27
1

A quick dirty way to this:

  1. Copy desired files to out(..)/system/lib or wherever after system.img has been built
  2. make snod

Other way is using Android.mk. Create a new dir in device tree eg libart-prebuilt. Put here your lib, then create an Android.mk file with content

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := libart-prebuilt
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_PATH := $(TARGET_OUT)/lib
LOCAL_MODULE_STEM := libart
LOCAL_MODULE_SUFFIX := $(TARGET_SHLIB_SUFFIX)
LOCAL_SRC_FILES := libart.so
LOCAL_MODULE_CLASS := SHARED_LIBRARIES

include $(BUILD_PREBUILT)

Now just add libart-prebuilt to PRODUCT_PACKAGES in your device.mk

Bartosz J
  • 178
  • 4
0

Also there's an option to add binary .so library as a product package, using PREBUILT_SHARED_LIBRARY option in .mk file: Include prebuilt shared library in Android AOSP or BUILD_PREBUILT https://stackoverflow.com/a/25682674/1028256

Mixaz
  • 4,068
  • 1
  • 29
  • 55