Easy tips to reduce your app apk size

Jitesh Dugar
Drivezy
Published in
3 min readSep 12, 2017

There’s already way too much talk about weight loss in humans and we would not want to add to the commotion. However, what about our apps? Is anyone concerned about their health — YES, WE ARE!

Apps come with a limitation that they have to be installed and they take up some space on a user’s device. Therefore, it is important that your apps are very light-weight.

The cost of an app is not only the store cost that you set for the app i.e. $0.99 or free. It is also the cost of data that is spent to install the app.

Let’s take a look at how much data costs in India v/s the US -

Let’s be honest, you don’t want your user to uninstall your application because of “Storage out of space” notification.

Here’s a quick and easy yet very effective 4-step weight loss programme for your apps so that the APK size can be reduced significantly -

  1. Use Proguard -

ProGuard is the most popular optimizer for Java bytecode. It makes your Java and Android applications up to 90% smaller and up to 20% faster. ProGuard also provides minimal protection against reverse engineering by obfuscating the names of classes, fields and methods.

You can enable proguard by opening your app level gradle file by writing minifyEnable true. In your gradle file, copy paste the following code:

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

There is no need to enable the proguard for debug build since it will increase the build time. Enabling pro guard will obfuscates your source code which will make it a lot harder to reverse engineer the app by making the codes unreadable. It replaces your long method names or variable names to something like a,b,c etc., so that not only it makes it harder for people to decompile your app but also reduces the code size.

Enabling proguard might lead to errors while generating release APK and to get rid of these you have

2. ShrinkResources -

shrinkResources” attribute will remove all the resources, those are not used anywhere in the project. Enable this in your build.gradle file by adding below line:

release{
//…
//…
shrinkResources true
//…
}

3. Compress PNGs -

This is the easiest way to reduce the apk size. You can either use WebP or SVGs instead of PNGs, these are expected to reduce your asset sizes by almost 30%.

However, using TinyPNG to compress PNGs also works well and reduces the asset sizes by around 60%.

4. Avoid unwanted libraries -

Use of external libraries increases the apk size and you might want to get rid of the unwanted ones from your build.gradle and rebuild the project.

Conclusion:

By applying above simple tricks the download size of our app reduced from 10.19 MB to 7.7 MB (~25% leaner!)

In addition to these simple tricks, there are many other tweaks that can help reduce the size of your app and make it fit!

Keep an eye on this space for more.

If you have anything that you’d like us to cover, just drop a line or two in the comments section. We’ll do our best to do something about it.

--

--