简体   繁体   中英

APK size increased 35mb when bumping min SDK from 21 to 24

Recently we bumped our min supported SDK from API 21 to 24.

Apparently this change caused our APK size to increase from 65mb to 103mb. From the APK analysis in Android studio, we can see it's all of the.so files that have basically doubled in size.

But why would that be? No gradle properties have changed, just the min sdk.

Any thoughts on how to decrease the APK size again?

Any thoughts on how to decrease the APK size again?

According to this answer on reddit and this issue on Google issue tracker that's because starting with API 23 the platform can read native libraries without extracting them if they are uncompressed.

If your minSdk is 22 or lower, they can't make use of this because on older devices there would be two copies of these libraries (unextracted and extracted from APK).

If you declare minSdk 23 or higher, building the APK with uncompressed native libraries should save space on devices because:

  • APK is compressed before download anyway, so download size doesn't change
  • after installation, there's only one copy of the library (uncompressed inside APK)

When I just tested this, the size after installation was actually higher with minSdk 23 compared to 22, contrary to what they say should happen. That is because the APK includes libraries for all ABIs . If I use only one ABI it is a bit smaller with minSdk 23. So until you startsplitting the APK or use App Bundle , you may want to set android:extractNativeLibs="true" in your AndroidManifest.xml .

Read official guideline aboutReduce your app size . To overcome issues regarding a big size apk, You can use ProGuard rules.

android {

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

Proguard obfuscates your code by removing unused code and renaming classes, fields, and methods with semantically obscure names which make the code base, smaller. The result is a smaller sized.apk file.

Open proguard-rules.pro . Add rules

DEMO

-keep class packageName.** { *; }
-keepclassmembers class packageName.** { *; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM