Shrink Your Code with ProGuard

Shrink Your Code with ProGuard

When I was creating the app "Check the Cheque" and uploading it to Google Play, I was wondering if its possible to shrink the app size. The app I was working on was like 2 MB and I knew that it was too big for an app that only had like one picture and only a few 100 lines of code. I searched on the Android User guide and it I came across the "Shrink Your Code and Resources" and I never knew that Android Studio had this feature. Also this is free because it's distributed under the GPL (General Public License). So I will compare how much smaller my app went from 2 MB, to 0.9 MB.

First thing first, I had one PNG image that was like around 500 KB file size and I wanted to convert it to WebP image. So going to the documentation at user guide named "Create WebP Images" show how easy it was to convert the image. However, it only works if you are working on an app that uses Android 4.3 (API level 18) and higher. So the image went from 500 KB to 65KB. Pretty good so far.

2MB to 1.4MB reduction OK, 1.4 MB, but that was a reduction of the image. Working with Proguard is simple: just go to your app's Build.Gradle (Module: app) and change the code from:

buildTypes {
release {
    debuggable false
    minifyEnabled false
    shrinkResources false
}

to this:

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

Now check out the new size. Final 900 KB size app Wow! From 2 MB to 911KB size android app.

We are not done yet, Proguard creates a file called mapping.txt and this is a valuable information that is used to share detailed crash and analytics data in your Google Play console and its in the left menu( click Android vitals > ANRs & Crashes) Location of (Deobfuscation files) mapping.txt file in a Mac And just upload the mapping.txt and you are set.  ProGuard to optimize and obfuscate your APK files, you can upload a ProGuard mapping file for each version of your app on the Play Console to deobfuscate your crash stack traces and help you better analyze your app's crashes

Special thanks to these web sites and people for teaching me about Proguard:

Maheshwar Ligade

ProGuard With Gradle


Author: jesueRocha, Jesue Rocha

Oh, I'm the cutest!

Just another programmer/network person.


Loves technology and retro video games. Likes to program on his spare time and rides a Kawasaki Ninja to the sunset 24/7.