Search code examples
androidandroid-studiominifylintandroid-proguard

How to reduce size of an apk file?


First of all, don't suggest me official documentation or this. When we build an app from Android Studio with predefined textview that simply displays "hello world", it generates an APK with more than 1.2MB. But some apps on playstore is available under 500KB with lot of features. I already applied all features of Android Studio like proguard, minifyEnabled etc. but that does not help. So, how can i achieve that level of compression?


Solution

  • When create new project from Android studio, the IDE automatically add some dependencies to your project.

    dependencies {
        // ...
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        // implementation 'com.android.support:appcompat-v7:26.1.0'
        // implementation 'com.android.support.constraint:constraint-layout:1.0.2'
        // ...
    }
    

    If you bundle support library and constraint layout library, your release apk size will increase rapidly even you don't add any code.

    You can get a very small apk if you remove support library and constraint layout library and just use all the system api.

    After remove the support library, you should

    1. use Activity rather than AppCompatActivity, YourActivity extends Activity

    2. do not use any theme from support library in your AndroidManifest.xml

    3. use FrameLayout to replace ConstraintLayout in your layout