Skip to content Skip to sidebar Skip to footer

How To Reduce Android Apk Size

I am developing application which contains below dependency Module level dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile 'c

Solution 1:

Instead of compiling full google services package, you can just call the packages that you need for compiling. There is a link below, kindly check the same https://developers.google.com/android/guides/setup

Before using the GCM, I suggest you to use Firebase Cloud Messaging, as google is shifting its base from gcm to firebase.

Link for Firebase Cloud messaging:-

https://firebase.google.com/docs/cloud-messaging/android/client

Points which can help you:-

You can use FontAwesome Icons in designs instead of images, that has a great impact on Application Size. Provide a specific size for each layout in dimen.xml for every resoultion.

If you are using image then you have to make sure that you are not inserting the same image for different screen. Try to use builtin icons of android as much as possible

Solution 2:

In versions of Google Play services prior to 6.5, you had to compile the entire package of APIs into your app. In some cases, doing so made it more difficult to keep the number of methods in your app (including framework APIs, library methods, and your own code) under the 65,536 limit.

From version 6.5, you can instead selectively compile Google Play service APIs into your app. For example, to include only the Google Fit and Android Wear APIs, replace the following line in your build.gradle file:

Replace

compile 'com.google.android.gms:play-services:9.6.1'//or the version you are using

with specific api's you need:

com.google.android.gms:play-services-gcm:9.6.1// and other if you need

List of dependencies for specific GMS apis can be found here.

Solution 3:

There are two useful techniques which you might be missing

  1. Optimizing Dex and Resources along with proguard

    This results in smaller code so should be used in release build only. Otherwise it will cause difficult during debugging. It can be achieved as follows:

    android {

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

You also need to focus on removing unused string from dependent SDKs.

  1. Removing unused configuration with ResConfigs

Many libraries like support/Google play services comes with string resources translate in too many languages. You might not be intending to support all of them. Using following way, you can control the size:

android {

    defaultConfig {
    ...
        resConfigs "en"
    }
}

This will remove all the resources that are not meant for English.

Post a Comment for "How To Reduce Android Apk Size"