Android开发如何有效减少APK的体积

本文主要整理自How to reduce APK size in androidhtml

1. ProGuard

Proguard能够删除无效的java code,显著地减少apk体积,可是要注意使用proguard以后要测试app,有时会致使一些bug。java

2. Split Apk

Split Apk能够为根据设备密度和ABI建立特定的Apk包,大大减小每一个apk的体积。android

3. ReDex

使用Facebook开源的ReDex,ReDex在压缩代码的同时,还能够提升性能。web

4. ShrinkResources

在gradle中使用ShrinkResources能够去除无效的资源文件,从而减小最终的apk大小,在build.gradle中使用shrinkResources:bash

release {
...
  shrinkResources true
...
}复制代码

5. resConfigs

使用resConfigs来去除非必要的本地化资源:app

defaultConfig {
...
  resConfigs "en", "hi"
...
}复制代码

6. Vector Drawables

Vector Drawables相比图片资源,要小不少。ide

7. debugCompile

使用debugCompile能够避免把debug期间用到的library打包到release apk中。性能

8. WebP file

使用WebP格式的图片资源,相比PNG和JPEG,WebP在保证质量的同时,压缩率更好。测试

9. 在须要的时候使用9-patch资源

10. 优化图片资源

能够使用TinyPNG, OptiPNG等压缩图片。gradle

欢迎关注公众号wutongke,按期推送移动开发前沿技术文章:

wutongke
wutongke
相关文章
相关标签/搜索