问题
I created a custom system image and put an additional APK into system/app. This kinda works, I can run the app, however native libraries are not getting loaded (loadLibrary() fails). When I call pm install
on the APK, everything works fine and the native library loads.
My conclusion is that the APK is not getting installed properly. I would appreciate any background on the behavior I observe. Is this the way it should be or am I missing something? At what time would the package manager install the APKs in app (or priv-app). Is there some sort of device setup that runs at some point?
回答1:
Pre-installed apps on AOSP aren't so much installed as kind of 'copied over'.
In order to have the prebuilt libs also 'copied over' you have to specify them in your Android.mk.
You do this by specifying LOCAL_PREBUILT_JNI_LIBS
on your Android.mk.
Here's an example:
LOCAL_PATH := $(call my-dir)
my_archs := arm x86 arm64
my_src_arch := $(call get-prebuilt-src-arch, $(my_archs))
include $(CLEAR_VARS)
LOCAL_MODULE := TestApp
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_TAGS := optional
LOCAL_BUILT_MODULE_STEM := package.apk
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_SRC_FILES := TestApp.apk
LOCAL_PREBUILT_JNI_LIBS := \
@lib/arm64-v8a/libnoise.so
LOCAL_MODULE_TARGET_ARCH := $(my_src_arch)
include $(BUILD_PREBUILT)
There is a useful tool called genandroidmk
which can generate this Android.mk for you automatically:
https://github.com/northbright/genandroidmk
回答2:
Follow these steps
Check libraries of prebuild APK. Install app in device (pm install) and then open android studio(apk installed device attached with pc), Click on View->Tools windows-> Device file explorer. It will open device explorer in right side, there go to data folder and check libraries in your app package name.
copy libraries and create a folder in aosp_source/external/yourlibfolder and paste your libraries there.
Go to build/target/product and write this code in your relevant make file.
external/yourlibfolder/yourlibname.so:system/lib/yourlibname.so \
external/yourlibfolder/yourlibname.so:system/lib64/yourlibname.so \
- It will add app dependent libraries in AOSP. Now when you add your Pre-built apk in AOSP it will work
来源:https://stackoverflow.com/questions/64689472/when-are-the-apks-in-system-app-being-installed