Skip to content Skip to sidebar Skip to footer

Error Adding Prebuilt Apk With Shared Libraries To Aosp

I tried to add a prebuilt APK to my Android build. The APK contains several shared libraries (*.so files). It compiles without problem, but I still get an error from the app indica

Solution 1:

I've had this problem myself, the reason is that when APK files are included in a build they are essentially bypassing the installation process. This installation process is the point at which any shared libraries are extracted from the apk and put in the appropriate place, ergo if that never happens the libraries will not be available. This is because packages that are built from source during the AOSP build either have their prebuilt shared libraries included during that build process or their libraries are also built from source, and in either case those libraries are put in the appropriate place.

For this reason in addition to the apk module itself you should add the following in the same .mk file:

include$(CLEAR_VARS)
LOCAL_MODULE := libapkwithso
LOCAL_SRC_FILES := lib/libapkwithso.so # or wherever your so is
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_SUFFIX := .so
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
include$(BUILD_PREBUILT)

Then add:

LOCAL_REQUIRED_MODULES := libapkwithso

Solution 2:

BUILD_PREBUILT calls prebuild.mk script. The description of this script is the following:

Standard rules for copying files that are prebuilt

It does not tell that the application will be installed. So I think that is why your application cannot find the libraries.

The solution is to extract libraries from the package and copy them separately from the application. The details how to do this you can find here.

Solution 3:

Files can also be be specified in aospSource:destinationOnImage format like this in the device-partial.mk when adding a custom vendor directory:

PRODUCT_COPY_FILES += \
    vendor/your-custom-vendor/your-device/proprietary/libx.so:system/lib/libx.so

You can add pretty much anything you like here (other than .apk files), and it will be copied to your image.

Solution 4:

My Instructions is not about your error! But it may be helpful for similar error

If you try to copy prebuilt apk using:

PRODUCT_COPY_FILES += $(LOCAL_PATH)/prebuilt/filename.apk

and you getting this error:

Prebuilt apk found in PRODUCT_COPY_FILES: ... , use BUILD_PREBUILT instead!. Stop.

You can remove this check my modify the file build/core/MakeFile and comment this lines:

define check-product-copy-files
$(if $(filter %.apk, $(callword-colon, 2, $(1))),$(error \
    Prebuilt apk found in PRODUCT_COPY_FILES: $(1), use BUILD_PREBUILT instead!))
endef

by inserting # before each line

Solution 5:

Too add multiple libraries to one apk one additional section (as in answer of Justin Buser) should be added for each separate library.

Post a Comment for "Error Adding Prebuilt Apk With Shared Libraries To Aosp"