Setting android:extractNativeLibs=false to reduce app size

后端 未结 3 1470
攒了一身酷
攒了一身酷 2020-12-06 10:29

I am not sure, if I got this right. It seems it is doing the oposite. If I keep the flag android:extractNativeLibs set to true, the app is taking about 70MB of user\'s space

3条回答
  •  萌比男神i
    2020-12-06 11:18

    There are some important preconditions for that to work though and that’s where things get more complicated:

    • The .so files inside the APK cannot be compressed — they must be stored.
    • The .so files must be page aligned using zipalign -p 4

    Update: The part below is only valid for Android Studio version 2.1 and lower. Starting from Android Studio 2.2 Preview 2 and newest build tools, the build process will automatically store native libraries uncompressed and page aligned in the APK.

    Fore more information: link

    Update: If at some point you sign your app manually, it matters when you invoke zipalign.

    Caution: You must use zipalign at one of two specific points in the app-building process, depending on which app-signing tool you use:

    • If you use apksigner, zipalign must only be performed before the APK file has been signed. If you sign your APK using apksigner and make further changes to the APK, its signature is invalidated.
    • If you use jarsigner, zipalign must only be performed after the APK file has been signed.

    Source: zipalign | Android Developers

    Android 6+ will prevent you from installing a misaligned APK with uncompressed native libraries. Older Android doesn't care and always extracts native libraries.

提交回复
热议问题