Reduce apk size android

不想你离开。 提交于 2019-12-20 01:14:29

问题


I am facing a problem with app size in android.

The scenario is,

I developed my android app in Android Studio 2.0 and the size of apk was 23 MB.

After that, I upgraded my IDE to android studio 2.2 and with little code modification the size of apk boosted to 51 MB.

I tried with prorogued and Lint but no advantage.

Can Someone help me to tackle the issue.


回答1:


1) Replace all of Images,Icons with vector drawable

2) Turn on pro guard like following goto build.gradleapp level

and put these lines

**shrinkResources true

minifyEnabled true**

3) Remove unused classes,drawable and methods and strings and use LINT's private method analyser which reduces method count

JAVA's Hidden cost

4) In android studio 2.2 and above they have added apk analyser tool in Build menu. Use that to analyse APk

5) if app size goes beyond 100mb use feature called split apk. there are two methods of spliting apk ABI and Density Splits




回答2:


Do this changes in your build.gradle(Module:app) file. It decreases the apk size almost (40-50)%.

android {
// Other settings

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

It reduces the size of classes.dex files and res folder.

It is recommended to that you should use webp file format instead of BMP, JPG, PNG for better compression.

For reference, you can use: https://developer.android.com/studio/write/convert-webp.html

For more details on apk compression you can refer:

https://developer.android.com/topic/performance/reduce-apk-size.html

https://medium.com/how-you-can-decrease-application-size



来源:https://stackoverflow.com/questions/40154269/reduce-apk-size-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!