Slim down your Apk size

YASH AGARWAL
Aug 23, 2017 · 3 min read
Source: https://cdn-images-1.medium.com/max/853/1*4SZr_5ZrGS1sibDiIrAn6Q.png

Android devices always have limited resources. They have a limited amount of battery, limited storage, limited processing power, limited RAM, limited internet connectivity … and the list goes on.

Recently we have released an Android application called “Mahadhan.This application is a one-stop solution for farmers with an aim of simplifying the Agri business experience for farmers in rural India. If you want to know more here is the play store page link to the application, you can download and check the functionality.

Some Apk size reduction technique

Smaller is always better. As a developer we always care about the application performance, design and user experience the most. But, most of the developer forget (or underestimate) one thing: Application Size. This is one of the key factors if you want to target next billion users with your application.

  • Use ProGuard: To make your APK file as small as possible, you should enable shrinking to remove unused code and resources in your release build.To enable code shrinking with ProGuard, add minifyEnabled true to the appropriate build type in your build.gradle file.

Note: Be aware that code shrinking slows down the build time, so you should avoid using it on your debug build if possible.

Refer: Link

  • Use Split APK: This allows you to create separate APKs that contain only code and resources specific to each density or ABI.

build.gradle

You only have to run assemble in Gradle projects

And finally you can find all the different apks build/outputs/apk

Refer: Link

  • Reduce resources where ever possible. Using shrinkResources attribute in the Gradle the resultant will remove all the resources which are not being used anywhere in the project. Enable this in your build.gradle file by adding below line:
  • Remove all alternative resource files that your app does not need by using resConfigs. As all the support libraries may have localised folders for the other languages which we don’t need.
  • Use Scalable Vector Graphics: Using Vector Drawable is one of the best way to reduce the size drastically.

Refer: Link

  • Use WebP file format: WebP is a method of lossy and lossless compression that can be used on a large variety of photographic, translucent and graphical images found on the web. The degree of lossy compression is adjustable so a user can choose the trade-off between file size and image quality. WebP typically achieves an average of 30% more compression than JPEG and JPEG 2000, without loss of image quality.

Refer: Link

These are small things and I am sure it won’t take much of your time to implement. But, in the end, you would end with a reduced/smaller app size and definitely a smile on your face. Please feel free to comment if you have newer techniques as well as ask questions. And, yeah! If this post helps you please do recommend and spread the word!

)
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade