• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

How to lower application size

Hello all.

I ran APK analyzer in android studio and found out that lib folder is taking too much space.

It takes 17Mb and total size of my app is around 20Mb.

Ja25rPT.jpg


How can I decrease size of the app?
 
It depends what libraries your app is using. What dependencies are in your gradle file?
 
You can further shrink and optimize your app by using proguard-android-optimize.txt instead of proguard-android.txt.

It would look like this in your build.gradle file...

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

The aggressive optimizations by proguard-android-optimize.txt can cause build errors. To fix these errors you can add the following rules to your proguard-rules.pro file...

Code:
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

-keepnames class * implements android.os.Parcelable
-keepclassmembers class * implements android.os.Parcelable {
  public static final *** CREATOR;
}

-keep @interface android.support.annotation.Keep
-keep @android.support.annotation.Keep class *
-keepclasseswithmembers class * {
  @android.support.annotation.Keep <fields>;
}
-keepclasseswithmembers class * {
  @android.support.annotation.Keep <methods>;
}

-keep @interface com.google.android.gms.common.annotation.KeepName
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
  @com.google.android.gms.common.annotation.KeepName *;
}

-keep @interface com.google.android.gms.common.util.DynamiteApi
-keep public @com.google.android.gms.common.util.DynamiteApi class * {
  public <fields>;
  public <methods>;
}

-keep class android.support.v7.widget.ShareActionProvider { *; }

-dontwarn android.security.NetworkSecurityPolicy

The above has been working great for me in my apps. You can experiment with these rules by adding one by one until your app builds without issue.

And here's a good tutorial to walk you through making your app smaller...
https://techstop.github.io/reduce-apk-size/
 
Last edited:
Back
Top Bottom