How we reduced our Android app size by 65%

By PregBuddy Engineering

PregBuddy
PregBuddy Engineering
3 min readAug 8, 2016

--

Most of the times it’s the small things in life that give you happiness. Android users love applications when they are of small size and easy to download on the go. Here is a story of how we reduced our Android application size by 65% within few days of launch.

Most of Android developers aren’t aware of app thinning methods in Android via which you can reduce your app size drastically without impacting the quality of your app. When we launched our first version of PregBuddy app on Google Play Store, it was a beast of 17.1 Mb size. For the first version, we did not focus much on the app size as we were keen on getting the product out in the market for users to explore. Soon after we launched, we started brainstorming about how can we reduce the app size as much as possible. After reading Android best practices, we came up with these list of items which we want to share with you today.

1. Use .svg format icon set

Its time to say bye to PNGs and welcome vector drawables. There are a couple of benefits of using them. We don’t have to worry about different device DPI’s and it also helps in reducing apk size. With Support Library 23.2, we can now use the app:srcCompat property of ImageView instead of android:src to make it backward compatible.

When you are downloading system app icon set from Google’s Material Design Icon Library, download .svg format instead of .pngs. This helped us reduce our app size by 1 Mb.

2. Compress PNGs

We are using PNGs for our walkthrough screens for all screen densities. The PNGs were of very high quality and size which just bloated up our app size! In PregBuddy v1.2 when we started optimizing our app size, we compressed our walkthrough screens and boom! The walkthrough screens were ~1/10th size it was before! (Yes! 1/10th). That’s crazy! We quickly created a build and checked the image quality in various screen densities, looked just the same. A quick Google search will give you a lot of tools that will help you compress your PNGs. We also got rid of the ldpi resources after seeing the Device Metrics shared by the Google Design team.

3. Use only specific libraries of Google Play Services.

Prior to Google Play Services 6.5 we had to compile the entire package. But now we can selectively compile it into our app. We are now just using Google Cloud Messaging, Google Maps and Google Location APIs.

4. Use Proguard

Proguard is used for code obfuscation and it also removes unused Java code from the dependencies. The result after using Proguard is a smaller apk file size which is difficult to reverse engineer. To enable proguard:

build.gradle

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

5. Shrink Resources

The Android Gradle plugin supports the ability to automatically exclude unused resources during the build process using shrinkResources gradle property. This alone reduced the apk size by ~0.5 Mb. To take advantage of this in your release builds, just add shrinkResources true to your release configuration.

build.gradle

android {
...
buildTypes {
release {
shrinkResources true
minifyEnabled true
...
}
}
}

These are small things and I am sure it won’t take much of your time to implement. But, in the end, you would end with a leaner app size and definitely a smile on your face. Please feel free to comment if you have newer techniques as well as ask questions. And, yeah! If this post helps you please do recommend and spread the word!

Yash Ladia is a passionate developer taking care of PregBuddy’s Android side of things. Yash graduated from NIT Durgapur in 2015. He has worked on several applications. A coder, contributor and tech enthusiast!

--

--