Search code examples
androidandroid-source

When are the APKs in system/app being installed?


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?


Solution

  • 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