Best practices for keeping slim your android APK size
App size is really a great matters when we make it live to play store. Think there are two applications which does the same thing. They have same UI but one is slightly heavier by 4–5 MBs than the other, which one will you go for? The answer is obviously the lighter one. That’s why we should always try to make our apk size smaller. There are many ways to reduce our apk size. Following are some approaches to be considered to reduce the apk size:
- Enable proguard and shrinkResources for removing unused code and resources. For enabling proguard and shrinkResources Follow this article.
- Drop unnecessary architectures by using ABI filters and APK splitting and reduce your APK size 50%.
- Specify the languages you support in your app by adding “resConfigs” in your gradle files: Add “resConfigs” in your gradle file to specify localization languages. Like if your app is in only one language (English) then simply specify resConfigs “en”).
defaultConfig {
...
resConfigs "en"
...
}
- Convert all Images from .png or.jpg to webp (One of the most important): Just right click on the drawable folder(drawable,drawable-hdpi, drawable-xhdpi etc) and click on convertToWebP (last option). You can also see this article for details.
- Do not include all important resources in the assets folder with APK. Download these resources at the time of application first start up.
- Use VectorDrawables if you are using simple small icons in your app.
- Use View’s tint property in xml to avoid multiple same icons but Different in color.
- It is good idea to just compress images before using it in your app. Also the font files used by you may be taking spaces you can try to find alternative.
- Use only the required libraries from Google Play Services.
- Use 9-patch images and avoid duplication of image or anything in the app code.
- Use “tools” attribute for dummy texts and avoid hardCoded string in your app.
You can analyse what is taking so much space in your application using “Analyse APK” feature in android studio.Go to “Build>Analyse APK” and browse to the APK file. It will show you what is taking so much space in application. This is because of Resource Images most of the time so try compressing big sized images.
…You may Join me on Linkedin, Github and Facebook.
Thanks for reading this article. Don’t forget to give claps if you find this article helpful. Happy Coding :)