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

后端 未结 8 1623
春和景丽
春和景丽 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条回答
  •  无人及你
    2021-01-03 10:43

    These 4 things reduce your apk size almost 50-60%

    • Replace proguard-android.txt with proguard-android-optimize.txt
    • Make minifyEnabled true
    • Add shrinkResources true
    • Add resConfigs

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

    Details:

    • proguard-android-optimize.txt is the more aggressive progurard configuration than proguard-android.txt.

    • shrinkResources attribute will remove all the resources, those are not used anywhere in the project.

    • resConfigs attribute will remove all the other localized resources while building the application. Here, it strips other than english resources.

提交回复
热议问题