Android app size analysis

Avijeet Dutta
Globant
Published in
5 min readJun 26, 2017

In my previous article, I talked about the app size analysis for iOS apps. In this article, I’ll be talking about the same for Android apps. Clearly, when you’ve 2B global active Users across the globe you would want your apps to reach out to the maximum based on your business. Also, this is important because a recent Google PlayStore statistics reveal that if the download size(OTA) of the app is greater than 100 MB increases the chances of canceling the download of such apps on the User’s devices by 20%.

And similar statistics apply for the install size of the app as well. Apps with more than 100 MB install sizes are 8 times more likely to get uninstalled from the devices.

So what should you do?

1. Use ProGuard:

This is enabled by default for release builds.

android {
buildTypes {
release {
minifyEnabled true
}
}
}

ProGuard is a whole program Java code optimizer. Mainly it does three important things:

a) It optimizes the code by changing the code representation without changing the core functionality.

b) It obfuscates the names of the types, methods, fields, classes, etc…And this increases the efficiency of the program.

c) Dead code elimination: This is the most important out of the three. An android program can be thought of as a graph where Classes, Methods, Fields as nodes and method calls and references as edges. Proguard keeps the direct entry points to the app and these entry points are nothing but the Android components(Activities, Services, Content Providers, Broadcast receivers, and custom application class) as defined in the App Manifest file.

Live Code vs Dead Code

2. Build multiple apks:

android {
splits {
density {
enabled true
}
}
}

This feature tailors down the app to be installed on specific devices based on its screen density and CPU architecture instead of downloading/installing the universal apk which has the additional resources that will never be used in the device. This basically means to split your apps based on screen densities and CPU architectures and then uploading them on the PlayStore together. And if you think this is a lot of work; then don’t worry Google has a better way of managing this through Google Play App Signing with additional benefits of heavy lifting the entire signing process of the app including safekeeping of the App’s release keystore to name a few.

3. Use Vector drawable:

android {
defaultConfig {
vectorDrawables.useSupportLibrary true
}
}

This simply means a single asset for all the screen densities. Android support library version 23.2 introduced the support for vector drawable backward compatible till API 14. Also, with Android N comes the support for the gradient in vector drawable. One important thing to note is complex vectors can slow down the CPU and RAM usage. So a thorough analysis should be done when you want to use vector images in the app. This is basically a trade-off between app size reduction vs app performance cost. Apps using vector images is comparatively smaller than the multi-app using xxxhdpi images.

4. Remove unwanted alternative resources:

android {
defaultConfig {
...
resConfigs "en", "fr"
}
}

The above Gradle configuration shows the app supports English and French only. This helps in eliminating unused resources from the app. For example, the string translations for the messages included in one or more of your app dependencies are in the languages that your app doesn’t support. Hence, with this setting, any resources for languages not specified are removed.

5. Use Downloadable Fonts

This is a new feature added in the Android platform. Google understood(through a survey of the top 25 apps on PlayStore) that most of the apps on the PlayStore use common fonts. Now since the fonts are bundled with the app, different apps on the device have duplicate copies of the fonts from the OS standpoint. Also, most of the fonts are not optimized for Mobile. Google came up with a solution to this problem through Downloadable Fonts.

Apps making use of common Fonts through Google Play Service’s Font Provider

Downloadable Fonts are on-demand fonts available through Google Play Service in the app. This is available from support library 26. This has many advantages viz. saving cellular data, phone memory, saving disk space to name a few. The font is fetched over the network when required. Using Font Provider helps you to make use of the entire slew of all the Google font catalogs(over 800) through Google Play Services.

6. Make use of APK Analyzer in Android Studio:

This tool is the best you can get to understand what’s being packaged inside your app. So use this tool wisely to make informed decisions for your app. And with Android Studio 3.0 and AAPT2 this brings even more on the plate to offer. Especially and most importantly the inclusion of ProGuard mapping to map the files to the corresponding obfuscated code on the release builds. This helps you to understand the granular details included in your app.

APK Analyzer depicting App Size break-up and method count information.

Not only this, but you should also always consider comparing the latest apk with the previous apk of an App. This helps you to understand the delta between two versions of the app and validate the same. Maybe remove unnecessary stuff for the code based on the analysis.

APK diff between two versions of an App

Following these techniques should let you tighten the waistline of your app as much as possible.

--

--