再谈Android应用瘦身

Android应用apk安装包的大小,虽然对于现在WiFi普及情况而言消耗流量已经微乎其微,但是,对于一款好的应用,对于一款负责任的应用,当然是越小越好了。

 

引言:

.应用越小,下载越快,也就意味着新用户能在最短时间内安装,体验应用,而不是看着通知栏里面的丑陋的下载进度条,盯着看几分钟(30-50M的应用很常见,网不好,下载几分钟很正常)就像这样...

 

. 随着应用的迭代,应用必须满足人们越来越高的体验需求,应用需要更多的代码,更多的第三方库,更多的资源文件,随着设备的分辨率越来越高,资源文件也是水涨船高,越来越大,最终导致应用大小一直上升.如果解压一个应用,查看他的分布,会发现,最占大小的是这3部分,classes.dex, resources.asrc , res folder. 有时候assets folder 也包含比较大的视频音频图片文件.there are some tools that can help you....whaha

 

正文:

优化点1:Apk Splits  对资源文件做优化配置

Density Splits

复制代码
android {
  ...
  splits {
    density {
      enable true
      exclude "ldpi", "tvdpi", "xxxhdpi"
      compatibleScreens 'small', 'normal', 'large', 'xlarge'
    }
  }
复制代码
enable: enables the density split mechanism
exclude: By default all densities are included, you can remove some densities.
include: indicate which densities to be included
reset(): reset the list of densities to be included to an empty string (this allows, in conjunctions with include, to indicate which one to use rather than which ones to ignore)
compatibleScreens: indicates a list of compatible screens. This will inject a matching <compatible-screens><screen ...> node in the manifest. This is optional.
 
Note that this will also always generate a universal APK with all the densities.
 

ABIs Splits

复制代码
android {
  ...
  splits {
    abi {
      enable true
      reset()
      include 'x86', 'armeabi-v7a', 'mips'
      universalApk true
    }
  }
}
复制代码
enable: enables the ABIs split mechanism
exclude: By default all ABIs are included, you can remove some ABIs.
include: indicate which ABIs to be included
reset(): reset the list of ABIs to be included to an empty string (this allows, in conjunctions with include, to indicate which one to use rather than which ones to ignore)
universalApk: indicates whether to package a universal version (with all ABIs) or not. Default is false.

 

优化点2:WEBP 另外一种谷歌推的web图片格式,小!!!

具体用法,或者兼容低版本,都有解决方案。

 

优化点3:Vector Drawables..同理WEBP....

 

优化点4: 手动压缩图片,神器 imageoptim ,官网:https://imageoptim.com/mac

 

 

https://www.novoda.com/blog/leaner-apks-with-custom-asset-minification/

 

posted @ 2016-07-12 15:19  狂奔的小狮子  阅读(1247)  评论(0编辑  收藏  举报