Simple ways to reduce your Android App size in no time

User visits your app, finds it useful, thinks to install it and jumps over to your competitor after seeing the mammoth size of your app — nothing can be scarier for an Android developer. .

In the modern world, a majority of the android users are struggling with keeping their device’s free space to not reach 0 and on top of that, the charges levied by their internet service providers. And then giving them an app with that a size, well you know, is just not fair. Culminating in wasting your uncountable hours of hard work and what not!

Bigger the better, as they say?? But nope….here smaller wins the race and is more loved!

Let us acquaint you with the simple yet proficient ways to reduce the app size in little to no time.

1️⃣ The res folder

The res folder consists of the images, XML and raw files. With using the “shrinkresources” in your build.gradle file, it will remove the resources which Proguard considers as not being used.

- While you have enabled “shrinkresources”, it should show in your app the reduced size. 
For eg., Removed unused resources: Binary resource data reduced from 2000KB to 1000KB: Removed 50%.

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

What does the above code do?
It’s simple — “minifyenabled” enables Proguard (we’ll talk about this later) while “shrinkresources” removes the resources which Proguard sees as not being used.

- Apart from shrinkresources, another important attribute is “resConfigs”. What it does — it removes the alternative resources — for different device configurations. 
In short — 
 — minifyEnabled — this will remove unused code.
 — shrinkResources — this will remove unused resources such as layouts or strings that are not referenced in your app.

2️⃣ Images compression

PNG images may look fantastic, however takes up a lot of space. We can use certain tools PNGcrush, ImageOptim or ImageAlpha etc. to reduce the PNG size. You’d need to choose the tool which best complies with your app flow.

On the other hand, you may go with WebP images. So how may this help? WebP is one of the latest image formats, which provides either lossless or lossy compression to the images. Lossless WebP images are around 27% lesser in size compared to its PNG counterpart. Also, the quality of the image will still be appreciable.

You can make use of the scalable vectors icon set from the asset studio in your app. Furthermore, you can use compressor tools to further reduce your app size. You can also use 9patch to scale images.

3️⃣ Proguard

Another very useful tool to optimize your Android App size. Proguard is a free Java class file used for code obfuscation. It helps remove unused Java code from the dependencies. After running Proguard, it will reduce the app size by making them compact. The main advantage of Proguard is that it is fast and can scan programs & libraries of many megabytes within seconds.

4️⃣ Usage of only specific libraries from Google play services

Before google play services 6.5, we needed to compile all the APIs in the app however, now we have the ability to compile whatever we need in our app, making it easier for us to track the method counts and thus culminating in reducing our app size. This will help you to hit dex limit easier.

To see available google play services dependencies, you may visit here
https://developers.google.com/android/guides/setup

5️⃣ The Lint tool (Static code analyzer)

The lint tool looks for structural code issues that can affect the quality and performance of your Android app. It is highly recommended that you rectify any errors that lint finds before making your app live.

You can run lint tool in your device with the gradle:

- For MAC/Linux — 
 ./gradlew lint

- For Windows — 
gradlew lint

On top of that, you can also customize your lint checking preferences in the lint.xml file.

You can do so like:

<?xml version="1.0" encoding="UTF-8"?>
<lint>
<!-- Disable the given check in this project -->
<issue id="IconMissingDensityFolder" severity="ignore" />
<!-- Ignore the ObsoleteLayoutParam issue in the specified files -->
<issue id="ObsoleteLayoutParam">
<ignore path="res/layout/activation.xml" />
<ignore path="res/layout-xlarge/activation.xml" />
</issue>
<!-- Ignore the UselessLeaf issue in the specified file -->
<issue id="UselessLeaf">
<ignore path="res/layout/main.xml" />
</issue>
<!-- Change the severity of hardcoded strings to "error" -->
<issue id="HardcodedText" severity="error" />
</lint>

(Taken from docs)

6️⃣ Reuse your code

An important way to reduce app size is by re-using your codes. Reuse it wherever you can. With Android providing standard codes which could be re-used for functions such as re-coloring assets, one can also use the ‘Rotate Drawable’ method to get necessary functionality. Similar techniques can be used to reduce your app’s file size and avoid resource duplication and dependency.

7️⃣ Removal of debug information

We suggest that you get rid of all debug-related functionalities from the app. The app most probably does not use this data, and the Android OS does not need it to run the app. A such, the debug information only exhausts space and should be removed.

To achieve this, all the functionalities related to debugging should be enclosed within conditional blocks.

If your app is still under construction and still needs debugging, then using debug symbols will help. However, if debug symbols yet appear when the release build is compiled, then we suggest that the Debug symbols be removed from native libraries like .so files. This can be done using the ‘arm-eabi-strip’ command, from the Android NDK.

8️⃣ Other recommended media formats

- Audio: AAC Audio is suggested for all audio resources. AAC accomplishes better compression at the provided quality, as compared to mp3/Ogg Vorbis. Raw formats like WAV should not be used.

- Video: By using H264 AVC, you can encode the video onto a resolution which is no larger than the screen resolution of the target device, if known.

Conclusion ⛔️

Designing is all about getting the best out above all the constraints. An unnoticeable quality drop will not matter when your app size is under scrutiny. Big app size may cost you an install. 
Remember, a user doesn’t judge your app through individual aspects, however as a whole. 
Above are some important points which you can make use of to bring justice to your hard work and uncountable hours of research.

Put all these things together and surely you’re in for a real treat. 🍧

Let us know how you found our blog and please do not hesitate to reach out to me should you have any questions. I’ll love to help you further. 😊

Originally written for WebReinvent Technologies Pvt. Ltd.- A pre-eminent Android Development Company