How to reduce Apk (.apk) size in android studio

后端 未结 8 1625
春和景丽
春和景丽 2021-01-03 09:50

When i run my app size of apk will 21 MB. even i enabled proguard. i use android studio to run project. in project files src folder has 8.62 MB size and lib folder size is 4

8条回答
  •  猫巷女王i
    2021-01-03 10:51

    There are a few techniques you can use to reduce the apk size:

    1. Proguard: In build.gradle file for app-level, add the following code

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

    2. Unnecessary Resources: Many times unnecessary resources are present in the source code. Inpect the source code by Analyze->Inspect Code. After the inspection ends, delete unnecessary resources.

    3. Webp images: Webp images have less size than png files and also it retains the original image quality. More to that webp images are natively supported in Android. Right-click the drawable(/mipmap) folder -> Convert to webp. Choose appropriate options which suits your need.

    4. Signed apk: The debug apk size is greater than the signed apk. Generate signed apk by going to Build-> Generate Signed Bundle/Apk->APK. Overall apk size is now reduced.

    5. Android App Bundle: If you are going to upload the app on Google Play, generate Android App bundle instead of apk.To generate app bundle go to, Build-> Generate Signed Bundle/Apk-> Android App Bundle. It will reduce your app size for sure. For example, my apk size of 10 MB is reduced to just 6-7 MB using Android App Bundle.

提交回复
热议问题