Showing posts with label Proguard. Show all posts

In this article, we will see some easiest way to reduce the APK Size of your application. The following methods discussed are very easy t...

How to Reduce the APK Size How to Reduce the APK Size

A blog about android developement


In this article, we will see some easiest way to reduce the APK Size of your application. The following methods discussed are very easy to do and remember.

1. Use Proguard:
Proguard is a code shrining tool used to reduce the APK size which removes the unused byte codes from the application and we need to take care after applying the Proguard.
Proguard can be enabled by changing “minifyEnabled” to true.
buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), ''

2. Use Lint:
Proguard is used to remove the unused byte code in Java side. But we need to make the same with our XML files. To achieve this, we can use Apache Lint and it can be run simply by calling
gradlew lint in your android studio’s terminal. It will generates an HTML report and shows the unused resources in the unused resources section. It will analyse the res directory of the application and not able access the assets directory of the application.

3. Use Vector Drawable:
Android supports Vector Drawable from the release of 23.2 support library and vector Drawable is an android version of SVG images in Android. We can convert SVG into Vector Drawable by Android Studio itself. It is small in size and colours can be changed by the image itself.

4. Optimize PNG images:
Optimize the size of the PNG images used in the application. We can optimize the images using some online tools like OptiPng or TinyPng

5. Shrink Resources:
Using shrinkResources attribute in the Gradle will remove all the resources which are not being used anywhere in the project. We can add this within the release scope of your app level build.gradle.
buildTypes {
    release {
        shrinkResources true

6. ResConfigs:
Remove the localized resources which are not needed by using resConfigs. As all the support libraries may have localized folders for the other languages which we don’t need.
defaultConfig {
  resConfigs "en", "hi"

7. Remove unused XML files:
You can make use of android-resource-remover is utility that removes unused resources reported by Android Lint from your project.

8. Remove Duplicates:
Use common functionalities and resources (or assets) to make code reusability and .reduce the line of coding.
For Example: Use colorFilter or tintMode to your ImageViews to avoid duplication of resources with different colours.

9. Remove Debug Libraries:
We recommend that you remove all debug-related functionality from the application. The application generally does not see or use this data, and the Android operating system does not require it to run the application. Hence, the debug information only wastes space, and should be removed.

10. Use Other Image Formats:
Android also supports WEBP images or 9-Patch Images. WEBP images are provides lossless compression rather than PNG or JPG images. WEBP supports from Android 3.2.

11. Use Methods Count Plugin:
Methods Count is an online tool used to the sizes of the libraries. Using this, we can find the alternative libraries with same functionality and less in method count.
Android Studio Plugin also available to do the same with the Android Studio IDE itself.

12. Use Facebook’s ReDex:
Optimize your final APK (after ProGuard) with Facebook’s ReDex. This should reduce the code size as well as potentially improve performance.
Note: We can use Split APK method to reduce the size of the APK. But the above mentioned methods are simpler than this. To know more click here.