Android Tutorials

5 Ways to Reduce APK Size – Android

Reduce APK size android

Why APK size matters?

As an app developer, apk size matters a lot. It may be a major factor for the users in deciding whether to install your app or not.
Reducing APK size is therefore should be taken seriously and you should see to it that the apk is not heavy.

The cost of your app is not only the store cost cost which you may put it as 0.99$ or FREE, but the total cost of an app also includes the data cost of the users incurred in downloading your app, the storage cost of the user’s device and also the time in which the user installs your app. 

We are seeing an exponential growth of smartphone users from countries like India, Indonesia, Bangkok etc wherein the smartphones cost less than 100$ and these devices ships with less RAM, low storage capacity and low processing power.

Exponential Growth in low end mobile devices

Thus, we need to take care that our app runs smoothly on these devices and it doesn’t take up a lot of space on their devices. You yourself might have uninstalled many apps in the past only because of storage issues right?Reduce APK sizeAlso, these developing markets have slow internet connection which will be mostly 2G, sometimes 3G and rarely 4G and the data costs are high. So data is precious to these users. Data is money.

 United StatesIndia
Cost of 1GB$10$3.81
Avg. hourly wage$26.19 / hour$0.31 / hour
Hrs of work to afford 1GB23 minutes12.17 hours

Today, in this post, we will see what are the 5 different ways in which you can reduce your apk size which will potentially get you more downloads and hence more revenue.

Methods to reduce apk size

I recently attended a Google conference and what I learnt from the Googlers was that the average size of an apk should be more or less equal to 10MB. Beyond 10MB, the installation conversion rate is less. That is, even though the visitors to your app listing decide to download your app, seeing at the apk size, they would cancel the install. Where as, if your competitors apk size is 5MB, they can use it to their advantage by mentioning that the app size is less than 5MB and may serve as an UPS to your competitor. That conversion rate is highly important. Let us see how we can increase the conversion rate by reducing the apk size.

  1. Enable ProGuard:

    The first and foremost thing that you should do is to enable pro guard in your manifest file. Enabling pro guard will obfuscates your source code which will make it a lot harder to reverse engineer the app by making the codes unreadable. It replaces your long method names or variable names to something like a,b,c etc., so that not only it makes it harder for people to decompile your app but also reduces the code size. 

    ProGuard not only obfuscates your code but also reduces the apk size

    ProGuard is the most popular optimizer for Java bytecode. It makes your Java and Android applications up to 90% smaller and up to 20% faster. ProGuard also provides minimal protection against reverse engineering by obfuscating the names of classes, fields and methods.
    You can enable proguard by opening your app level gradle file by writing minifyEnable true. In your gradle file, copy paste the following code:

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

    There is no need to enable the proguard for debug build since it will increase the build time.

  2. Remove unused resource files

    You many have noticed that resource files like images, audio files, gifs or the font files in your asset folder are the major factors contributing to your apk size. 
    There is high chance of you including many resources over the course of the development that many of these would have been unused and left as it is in the res folder. You can remove unused resources manually or by going to Refractor > Remove Unused Resources tab at the top. This will search and show you the resources which are unused in your application build and will let you delete these. This will surprisingly reduce your apk size.

  3. Use vector drawables and 9 patch

    Use scalable vector graphics for your icons, small buttons inside your app, etc. By doing this, you can use the same file to scale across multiple resolutions so that you don’t need to include different resolutions files of the same image. If you have an svg or a psd file of your logo or image, go to File > New > Vector Asset and select local file and complete the process. You will get a single file which you can use across the different screen densities. 
    Also, you can use 9 patch tool to create resizeable bitmap images that automatically resize to accommodate the contents of the view and the size of the screen. You can learn more about it here.

  4. Remove unsupported Architecture

    If your app supports only x86 or armeabi-v7a or only a few of the architectures you can specify using the abiFilters property in your gradle file. The ABIs listed are the only one to be supported in the app. This will remove unnecessary support files and what not related to unsupported architectures. This will reduce the apk size to a certain extent.

     abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a'

    Include those architectures which are supported by your app. If you still install the app over the unsupported architecture the app will not be installed and will return with INSTALL_FAILED_NO_MATCHING_ABIS error.

  5. Spare Translations

    Many of the apps support only default English language and a few of them support 5-6 other languages like Spanish, French, Hindi, etc. 
    We do not care about the languages we don;t support and leave it as it is. This will make the studio to include all the default strings and style information of more than 80-90 languages which will redundantly increase the app size. 
    We will be knowing what all languages we support, so we can remove the unsupported language strings totally from our app. 

    It’s a waste to include unsupported language default strings
    By doing this, I saved 300KB from an apk of size 2.6 MB to 2.3MB. Just 1 line of code and saved me 300KB of precious data. Imagine 300KB downloaded by 1 million users, that’s close to 300GB of  waste data. 
    Include the following code in your gradle file and see the magic.

    For single supported language: 

    android{
    defaultConfig {
    ...
    resConfig ("en")
    ...
    }
    }
    

    For multiple supported languages: 

    android{
    defaultConfig {
    ...
    resConfigs "en" , "fr"
    ...
    }
    }
    

    After you make the above change and upload it to playstore as an update, the Google Play Console will show you a warning that you are removing the languages, ignore it.

Final Words:

By following the above 5 methods you can significantly reduce your apk size and bring your app size close to that magic number of 10MB if not less than that. As explained at the beginning of this post, reducing the size will have direct impact on new installs and also retention rate.

Hope these methods helped you to a certain extent. If you liked this post, perhaps you will like some of my other posts too. Please bookmark this page or like us on Facebook for regular updates on new posts.

Please comment down if these tricks helped you or if you have any queries.

About the author

Darshan Gowda

Follow me on Facebook, Google Plus

Leave a Comment

error: Content is protected !!