How to reduce apk size in android | Illustrative steps

Reducing the substantial size of android applications helps you to build your downloads. Did you abstain from downloading huge applications?

What is apk?
Android application package file (APK) is the file format used to distribute and install application software and middleware onto Google’s Android operating system. It is generally have .apk extension.

why you should keep size of apk small?
1)You may face problem in uploading apk>50Mb on playstore
2)User avoid downloading larger applications

How to reduce size of apk?
2)Vector drawables
3)Optimise png images
4)Remove unused images
5)9 patch images
I will elaborate each of them individually.

This is what you are looking for? Click below

(1) Optimizing images:-
Images constitutes almost 80% of apk size so optimizing images reduce apk size to much extend. Recommended formats for images are png and jpeg. Following are steps to optimize image:-

  • Search for png/jpeg optimizer in your search engine.I use TinyPng but you can use any of your choice.

Upload png image at TingPng

  • upload image and optimise it

Image of size 38.7 Kb compressed to 10.2 Kb

  • Replace optimized image with old image in your res/drawable folder.

(2) Proguard :-
Proguard works on the Java side (text files). Unfortunately, it doesn’t work on the resources side so enabling Proguard will save a little bit size-wise.

But remember “great things are done by a series of small things”.

Update you app file under gradle folder.

module's build.gradle file help reduce apk size in android
figure:-module’s build.gradle file

minifyEnabled is responsible for  shrinking your code files (e.g. Java). It is the main feature of ProGuard, and helps to shrink your APK as well as making it difficult to reverse engineer.

shrinkResources is used to remove unused resource files (such as images and other assets). For example, if you are compiling with an Android library, but you are not using some images in that Android library, they will not be included in the final build.

(3) Remove Unused resources:-

  • Just go to Android Studio-> Menu->Analyse->Inspect code
  • You will see dialog like this:-

Dialog appears when you click on inspect code

  • Click on OK button and you will see something like this
Unused resources
Unused resources

When you browse through the reported items, you will notice that many of them can just be ignored to reduce apk size. For instance, spelling, which catches a lot of non-typos in strings However, stuff like the items under Android lint and Declaration redundancy are highly interesting, and will be a great help for a newbie like me.

Expand each of them and inspect them individually and suppress them if you want.I am showing how to suppress Android Lint. Also you can avail more options with right click on respective items and then click on Exclude->Delete.

Inspect unused resources and suppress themThis is what you are looking for? Click below

(5) 9-patch images:-
converting your image to 9 patch image can save you a lot for you.Here are 2 ways and you can follow any of one.

  • Simply upload your image at Android asset studio and directly convert your png image to 9 patch image.You can see that your image extension changes to .9.png . Now replace this image from image in  your res/drawable folder.
  • You can directly convert png image to 9 patch image from IDE(Android studio).Android Studio now has this option available by right-clicking on the image file in your res folder in android studio, then selecting Create 9-Patch file. You can then open the newly created 9-patch file and start editing!.
Convert png image to 9 patch image from Android studio
Convert png image to 9 patch image from Android studio
9 patch image
9 patch image

Edit image and delete .png image .Keep .9.png image. Clean project and run it.This is what you are looking for? Click below

(5) Vector drawable:-
This lets you create a drawable based on an XML vector graphic. It reduce the apk size since you only have 1 Image vs having multiple in different folders for different screen densities(mdpi.xdpi,xxdpi etc).

You might be able to make your own drawables for certain images. If you want plain background for your app then you can do it from vector drawable for different shades and colors.

Some useful tips to reduce apk size :-

  1. Check if there still exist drawable-Ldpi folder then it’s time to delete it because there are no more devices with ldpi screen resolution.
  2. Recommended media formats- If your application relies heavily on images, audio or video, APK size is reduced by using certain media formats. I recommend you to use following media formats for images ,audio and video.
  • Images: PNG or JPEG
  • Audio: AAC Audio is recommended for all audio resources.
  • Video:Use H264 AVC

7 thoughts on “How to reduce apk size in android | Illustrative steps

  1. Size may also come from Android Compatibility library and Google services and 3rd party lib/sdk (for example Guice, Guava)
    How to reduce those?

Leave a Reply

Your email address will not be published. Required fields are marked *