I have an APK file with the bundled native libs. When I install them using adb the libraries are correctly created at <path-to_package>/lib/, But I have to integrate my apk to the build system along with the Android.mk file. What I need to add in the make to get the libs extracted on to the target
            Asked
            
        
        
            Active
            
        
            Viewed 2,890 times
        
    0
            
            
        - 
                    It's not clear what you mean by _"integrate my apk to the build system along with the Android.mk file"_. How did you build the libraries in the first place? – Michael Nov 09 '20 at 15:10
- 
                    I got the libs from third party. And now I have apk, I just need to write the makefile which copies the apk and native libs on the target. – Vimalakshi Adiga Nov 09 '20 at 15:15
- 
                    See https://developer.android.com/ndk/guides/prebuilts – Michael Nov 09 '20 at 15:17
2 Answers
1
            
            
        You can find an example in AOSP, e.g. in external/chromium-webview project:
- using Android.mk(outdated): https://android.googlesource.com/platform/external/chromium-webview/+/refs/heads/android10-d4-release/Android.mk
- using Android.bp: https://android.googlesource.com/platform/external/chromium-webview/+/refs/heads/master/Android.bp.
Also some related topics were already discussed on SO:
 
    
    
        Mykola Khyliuk
        
- 1,234
- 1
- 9
- 16
- 
                    This will not extract the libs into lib/abi folder.. Even I checked chromium-webview on the target. It just contains apk not lib/abi – Vimalakshi Adiga Nov 12 '20 at 10:25
- 
                    Yes because they are packed into APK archive, if you want to see them physically e.g. via ```adb shell``` you need to set ```android:extractNativeLibs="true"``` in ```AndroidManifest.xml/application```, it is already discussed here: https://stackoverflow.com/questions/63219377/where-to-put-c-so-library-needed-for-my-android-application – Mykola Khyliuk Nov 12 '20 at 10:47
- 
                    Yes, I have added 'extractNativeLibs=true', But does not help. But when I install the app manually via adb it creates the libs at lib/abi. – Vimalakshi Adiga Nov 12 '20 at 12:38
- 
                    Also I need path of these libs in my application, is there a way to get the path of these libs embedded in apk itself? – Vimalakshi Adiga Nov 12 '20 at 12:53
- 
                    ```String pluginDir = new File(getPackageCodePath()).getParent() + "/lib/" + convertABItoLibDir(Build.SUPPORTED_ABIS[0]);``` – Mykola Khyliuk Nov 12 '20 at 13:07
- 
                    ```convertABItoLibDir``` does matching between ABI name and lib directory name, because they don't always fully match, e.g. ABI "arm64-v8a" corresponds to "arm64" lib folder. – Mykola Khyliuk Nov 12 '20 at 13:12
- 
                    Thanks for your support. I have extracted the libs manually and using them as per https://stackoverflow.com/questions/64735430/adding-pre-built-apk-vpn-in-aosp-crashes But I try considering your suggestion embedded libs usage – Vimalakshi Adiga Nov 12 '20 at 13:51
0
            
            
        - If you have libraries then 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(e.g handhel_system.mk) for each of library. Replace yourlibname with each library name 
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
Create a folder in packages/app/yourappfolder and paste APK and make file there
This should be your make file
# Adding Apk as system app in AOSP
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := Appname # It should be your apk name, and folder name should also be same 
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_SUFFIX := .apk
LOCAL_MODULE_CLASS := APPS
LOCAL_CERTIFICATE := platform
include $(BUILD_PREBUILT)
 
    
    
        semw
        
- 137
- 1
- 1
- 10
- 
                    
- 
                    You can mention them in apk make file like this ```LOCAL_PREBUILT_JNI_LIBS := \ @lib/arm/yourlib1.so \ @lib/arm/yourlib2.so \ ``` – semw Nov 12 '20 at 05:53
