How to load native library directly from APK

Starting from Android M, you can load native library directly from within the apk itself. Unfortunately, until now, there is no official document and neither Android Studio nor Eclipse ADT supports this work flow.

Here I gave you step by step instructions for how to do that.


To enable this, you only need to set extractNativeLibs to false in AndroidManifest.xml and build your project with Android API level 23 (or above), and target at API level 23.



This is the difficult part. You need to do below manually. Let’s hope Google can automate this in Android Studio soon.

Export an unsigned apk

With Eclipse, right click on your project, export unsigned apk.

With Android Studio,

    1. Click on the drop down menu on the toolbar at the top (usually with android icon and name of your application)
    2. Select Edit configurations
    3. Click plus sign at top left corner or press alt+insert
    4. Select Gradle
    5. Choose your module as Gradle project
    6. In Tasks: enter assemble
    7. Press OK
    8. Press play

Unzip this unsigned apk

For example, into a new folder ../unsigned

Zip this folder again with STORE option

For example, you can use 7zip, from within ../unsigned, select all in Windows Explorer, right click, select 7-Zip, Add to archive, choose ZIP and STORE option. STORE means no compression used within the zip file, zip serves the same purpose as tar.

Rename the new uncompressed zip file to *apk

Sign this apk with your keystore

jarsigner -verbose -keystore appkey.keystore -storepass pa$$w0rd -keypass pa$$w0rd app_unsigned.apk MyKey

jarsigner and keystore are standard Java SDK features, not specific to Android. Please check official reference for Java if you are not clear how to use it or don’t have a keystore.

Page align with zipalign (find this in your Android SDK/build-tools/).

p is page alignment for STOREed native libs; 4 is for 32 bit arch, use 8 for 64 bit.


Now you are good to install the APK

If anything goes wrong, the apk will not install. When not extracting native lib from apk, Android M will refuse to install the app if the native libs are not in STORE option or page aligned.

To verify, after installed the apk, you can check there is no *so files in,


Happy Hacking -_-