3

I have an APK that contains java code and some .so files. I have built the APK in Android Studio and now this APK needs to be part of /system/app/ folder on my custom ROM.

Java code + .so = APK

To include it in system/app/, I am having the below build script in Android.mk file and calling it from device.mk file.

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := utility
LOCAL_MODULE_CLASS := APPS
LOCAL_CERTIFICATE := platform
LOCAL_SRC_FILES := utility.apk
include $(BUILD_PREBUILT)

After building the image, I find my APK crashing, and the log says "Cannot link executable" and all .so files seeems to be missing. However, the APK works if I use adb install utility.apk.

Can someone tell me what is that I am missing in the buildscript that is causing .so files not being available.

P.S.: I searched inside /data/data/com.org.utility/, /system/lib/ folders, but no .so files were found. But if I use adb install, .so files are found inside /data/data/com.org.utility/lib/x86/ folder.

1 Answers1

1

I don't remember in L or M, there is a bug in the build system.

The so in the apk which is built into system/app or system/priv-app cannot release into the system. But the third party app can release there libs by PackageManagerService.

One solution: 1. Released the so in the apk manually. 2. Add so related to the Android.mk, for example:

    LOCAL_PATH := $(call my-dir)
    include $(CLEAR_VARS)
    LOCAL_MODULE := test
    LOCAL_SRC_FILES := libtest.so
    include $(PREBUILT_SHARED_LIBRARY)
  1. Add this module name to PRODUC_PACKAGES micro.

These so in your app will be built to your system/lib or lib64.

Good luck.

lemac
  • 174
  • 1
  • 5
  • This approach works if we have access to the codebase. For third party APKs to be included in system/app, this solution cannot be applied. – user3022690 Aug 21 '18 at 09:28
  • @user3022690 You can extract all **.so** files from the third party APK yourself. After all, it's just a signed ZIP file. I believe you don't even need to repackage this APK, the obsolete **.so** files won't hurt. – Alex Cohn Aug 21 '18 at 10:32
  • 1
    Well, 1. if you can make apk by Android.mk, and you can make so also. 2. If you cannot access the source code, and you need to put your apk to system/app, you got the root permission, in this situation, you can release the so, and put them to system/lib also. 3. If you don't have root, you have to install the apk by adb or some other method, PMS will release your libs, and this problem will not happen. – lemac Aug 21 '18 at 12:03