Reduce Android app bundle size

Users often opt for small Android apps!

Curioustale
4 min readJul 15, 2023
Photo by ilgmyzin on Unsplash

Android apps are a huge industry. Every major and minor platforms have equivalent Android apps for their users. The Android market is booming with billions of apps. But not all apps succeed. If you are one of the developers building an Android app to make a living or to make an impact you want to make your app as effective as possible.

When you search the app store for a music player, you will see a number of music players, what are the details you see on the listing? There are details about the app's icon, title, developer name, rating, download size, and number of downloads. Out of all this, you can take control of the icon, name, and app size. Most users looking for Android apps often look for compelling icons, names and especially app sizes. If a simple music player is 50MB, no one would like to download it, there is no reason for a music player to be this big in size.

No matter how big the storage of the latest smartphones is, most users would want to download apps that are small in size. There are also other advantages of downloading small apps like the time from download to testing the app is small, small means it is optimized, and it doesn’t have any bloatware, also data savings.

I will be discussing the following tips to reduce app sizes

  1. Updating your gradle file

Add the following flags to your app’s build.gradle file.


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

These two flags ensure that the libraries you used will be scanned to remove unused resources. I have seen these flags are very effective and this is the first thing I would do while developing a new app.

Also, make sure the proguardFiles uses the proguard-android-optimize.txt which is stricter pro-guard rules which will not allow some extra code to be packaged. You can read more on this topic.

There are a few more flags that can help but the other one I would like to mention is useLegacyPackaging use this only if you are not using .so libraries.

android {
packagingOptions {
jniLibs {
useLegacyPackaging = false
}
}
}

2. Removing unused resources

While developing an Android app you will test out the app with different resources like fonts, images, external code, dependencies, etc. Most of them might not be required in your final builds. The way you can remove these unused resources is by simply following the steps.

  1. Open the project in Android Studio
  2. Right-click on the app and click on Refactor
  3. Select the Remove the unused resources option and then click Preview to see the files that are being affected.
  4. Once everything is verified click Refactor

This should delete unused resources including unused strings in your source code. This is an effective step and most developers will forget to do this.

3. Shrinking your images before using them

Most apps will have images to showcase features or upcoming events or promotional content. These images might not be compressed and bloat your app severely.

A few suggestions to improve on this, if your images are gradients, icons, or indicators then you should use vector graphics, or custom drawable built using XML, By vector graphics I mean using svg they are small in size and are just text in a general context. These svgs are rendered on the fly while using the app. If your svgs are small they would be very efficient.

For graphics, instead of bundling them with your app, fetch them from external servers, it could be Firebase or your own servers. This will give you the freedom of changing the graphics whenever you want and it won’t affect the size of your app. Use libraries like Glide which are much smaller in size.

4. Using fewer dependencies

Your app might require some dependent packages to perform some tasks. There also might be a case that you added a few dependencies which you no longer require and can be deleted. Go to your build.gradle and remove these dependencies.

There will be some dependencies you cannot remove and are required for the app to function, these are fine. If your app is using custom design components and is not directly dependent on the material design provided by Google. You can remove these material design dependencies which might be added when you first bootstrap a project.

You might want to consider these practices before you start the app cause it will be hard to do after you have built all of it.

Prepare a checklist

If you want your app to be as small as possible consider the above methods and create a checklist before deploying to the Play Store.

a. Check for build flags minifyEnabled and shrinkResources
b. Refactoring unused resources.
c. Compressing images if any.
d. Removing unused dependencies in your grade.

Follow for more! Join the discord!

--

--