Understanding Android APK and reducing size [Part 1]

Saurabh Singhal
MindOrks
Published in
3 min readSep 17, 2016

How I decreased my app size to 70% Using APK analyser

Every Android developer’s work is not just to build apps, but engineer them and get best possible results. Making an app with 2 screens and 5 MB size is just unacceptable.

The problem:

While working on our app, some users reported that the app was too big considering the functionality.(11 MB)

The Journey:

So I started to explore methods to minimise the size. There were a lot of tools like ProGuard which reduced the size to 9 MB but that still was not enough. I heard about an event happening all over India about the android studio and its features(Android Studio Roadshow), I attended it and found some great tools to inspect our apps and performance monitoring. One of them was APK analyser which caught my attention. Available at Menu bar > build > Analyse APK.

When I used it on my app, I found that most of the space was being used by lib folder, some google searches returned that it contains lib files that are used to support multiple devices.

old APK

But we are running an app on one device at a time, right? then why package all into one and waste space? That’s just so you can have one universal APK for all devices. but on the expense of HUGE size? No way.

Digging deeper into the problem, I found that those libs were added by Realm. So how to solve this issue?

The Solution:

I enabled a feature in the android studio called APK splits. This feature generates multiple APKs for multiple devices as configured. Just add these lines to your app level build.gradle to enable APK split.

I hit the build button and now android studio generated 6 APKs, for different CPU architectures (ARM, MIPS, x86) and voila!

Running APK analyser again revealed that because of splitting, now lib folder only had 1 lib according to the CPU. And the app size was just 68% of the previous one.

ARM64 specific APK

The lib folder size was reduced from 10 MB to mere 3 MB in seconds! Hell yeah, Mission successful!

Now we just need to make sure we provide correct APK to correct tester so there won’t be any compatibility issues, this can make the development process a bit complex, but with results this overwhelming, I had to do this! If you are uploading the app to Google Play, it handles the situation gracefully and shows APK according to the device automagically!

But how do I upload multiple APKs at once to Google Play and handle cases when the same device supports multiple APKs? find out in the next part here!

Let me know your thoughts and your queries in the “response” ;) below.

Until next time.

For more about programming, follow Mindorks , so you’ll get notified when we write new posts.

Check out all the Mindorks best articles here.

--

--