The Art of download size optimization for Android applications in practice

Ayman Alshaikh
7 min readAug 10, 2021

--

Hey, guys! I hope that everyone is doing well.

So today I decided to share one of the most important app-releasing practices that I’ve learned during my android applications development journey. It can save you lots of time, and also save your end users some MBs and you will end up with an improved daily downloads rate.

Let’s get a quick start by showing the importance of optimizing your Android app. The size does matter, especially for apps targeting users in the developing countries market (more especially Sudan).
A recent study showed that almost 70% of users consider app sizes before installing them.

Technically speaking, the impact is being shown on how fast your app loads, how much memory it uses, and how much power it consumes.

Average Android applications download size heat-map

First, you should figure out your current app situation of size distribution across the app components, since it will be easier to plan your optimization steps…

To get started you should have to analyze your app build by using Analyze APK tool on Android Studio, it accepts both .apk and .aab formats

Now you have a clear vision of how much each component on your app is contributing on the app build size so…👇

Let’s GO ✨

1. Code Shrinking

i. Remove Unused Libraries

The analyzer will help you to know exactly how libs “implementations” are contributing to the application release size since it will be easier to have a decision to remove the unused ones.

ii. Use Proguard

So from now on I’ll assume you removed all unnecessary libs you don’t want, you are only keeping the needed ones, but some of them still taking a considerable size?! This is one of the problems Proguard is here to solve.

Proguard has 2 main objectives:

1- Minify: Remove unused code in your application

2- Code obfuscation: Rename/shorten the name of classes, methods, variables and so on, this is also highly recommended for security reasons!

Just change minifyEnabled to true in you build.gradle file.

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

Notes regarding using Proguard:

  • Make sure you are aware of what you are going to do, this may end up with a broken app if not used properly, you have to set the right rules by checking for each third-party library Proguard rules requirements.
  • If you are not using serialized names on your HTTP response models you should exclude these models from being processed by Proguard.

Learn more about Proguard: https://developer.android.com/studio/build/shrink-code

2. Optimize app resources

i. USE Vector Drawable

Using Vector Drawable is one of the best ways to reduce the size significantly.
To get started using Vector Drawable you only want to work with UI Sheets then you just have to import all needed icons in an SVG format then use Vector Asset which will convert it from SVG to Vector Drawable.

ii. USE WEBP Images format

The WebP image format is the preferred one for Android apps which is being developed and highly recommended by Google.
This can be done simply by converting the existing image assets from PNG/JPG into WEBP since it could optimize the app size to be the lowest up to 60% of the original size while keeping almost the same image quality, on my case one of the major use cases: is to convert the full screens images which most probably being used on the App intro screens.

P.S. Mohamed Moawia El-Bashir noted that AVIF is even better than WebP.

iii. Compress Images

Sometimes you will find your app is still using PNGs so is highly recommended to compress them using image quality tools like TinyPNG.

iv. Ship only the languages your app is using

Give a look at the app components above, by default, the build system is shipping multiple values folders “localized resources” for each language which will somehow affect the app size by removing all unused language resources.

You only have to override the default resconfigs configurations by adding resconfigs with the suitable as shown below into your default config section.

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

v. Shrink resources

This will remove all the resources that aren’t being used on the project
apply it by adding shrinkResources true to your release build type.

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

vi. Use Lottie Animation instead of GIF files

Using Gifs for animated graphics scenes in SplashScreen is a very bad practice rather than its huge size contribution it consumes more memory resources and delivering a very bad quality, you should avoid it, instead, you should use Lottie animation.
You can find a couple of ready-made animations online or it’s better to ask your UI/UX designer to customize a suitable one using Adobe Effects then the animation can be exported in a tiny JSON format can be rendered using Lottie animation library.

https://lottiefiles.com/
https://github.com/airbnb/lottie-android

Lottie Animation usage sample

3. Advanced Tips and Tricks.

Woah Congrats! You did your best optimizing your app size so as a reward you will find below two Pro tips.

The first one will let you know a better way to deliver your application to your end-users.
The second one it’s a nice trick I learned from a TikTok engineering article using a tool written by ByteDance.

i. Implementing Multi-Module app architecture: Dynamic Feature:

Case Scenario: GO

At GO we are implementing this in 2 different modules which are not necessarily being shipped within the initial downloaded package from the Google play store, we used to pack two modules, Rating Module, and a 360 panorama image previewer “handling the 360 panorama photos for previewing bus stations” because they are depending on a couple of animated emojis and binary files which are contributing by almost 2.5 MB, these two features can be downloaded later on after the user successfully installing the base application.
https://play.google.com/store/apps/details?id=com.goteclabs.customer

Case Scenario: Mobile Games

I am developing some mobile games and I am considering one the main reasons that helped me a lot to accomplish the 1M+ downloads is the game download size, yes it’s a competitive advantage for sure, the case here is at some point I used to implement a voice chat feature, and as a result of implementing it will impact the overall game size about nearly 70% because voice streaming implementation is depending on heavy binary files, the challenge here is to solve this problem without sacrificing the initial download size of the game as I mentioned on the introduction since it will affect immediately the daily download rate.
https://play.google.com/store/apps/details?id=klma.online.ayman

The Dynamic Feature module implementation comes to solve these problems.

I won’t go into its implementation details, but the main point here your dynamic feature will be requested to be downloaded only once at the moment of being needed by the end-user.

This article will help you to get onboard by implementing dynamic feature modules: https://medium.com/mindorks/dynamic-feature-modules-the-future-4bee124c0f1

ii. Resources obfuscation: using aabResGuard:

AabResGuard is a resource obfuscation tool used by the leading social app Tiktok.

This is meant to be acting the same as the Proguard, but the main difference here is the Proguard is only taking care of the executable bytecode, not of the app resources “/res

Hehehe, In terms of optimizing your app size, this will be your final bullet!

Tool configurations
Before and After

It will help you reduce your app size for some KBs and in most cases not more than 200 KB, it’s better to mention that it’s also highly recommended for security reasons, I already implemented it on multiple projects I am working on.
Source: https://github.com/bytedance/AabResGuard

Results?

Before a couple of months, I joined a startup in UAE called Aleem, after I had finished the handover process since the code implementation was well written, I decided to start optimizing the current download size from almost 8MB to 5 MB, which noticeably accelerated the app downloads from 500+ to 10K+ in a couple of weeks.

I guarantee you by following these steps might help you a lot to keep your application on the 5~10 Mb download size average.

See you next articles 😄❤️

If you find something wrong or anything else, you can always reach me at

— > LinkedIn

— > Twitter

Your feedback is well appreciated, Thank you!

--

--

Ayman Alshaikh

A cool Software Engineer @Tasliya, @uqudo & @GoRideSD, busy doing great apps, games.