Android apk大小优化方案
1.减少图片的体积 SVG IconFont 使用
svg格式的不能直接使用 需将图片转化成vector的xml文件
//指定维度 vectorDrawables.generatedDensities('xhdpi','xxhdpi')
//兼容性 vectorDrawables.useSupportLibrary = true;
// 使用 app:srcCompat = "...";
https://developer.android.google.cn/studio/write/vector-asset-studio
2. Tint着色器
相同的图片改变不同的颜色
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="false"
android:src="@mipmap/ic_launcher"
android:tint="@color/tint"/>
新建color文件夹
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="@color/colorAccent"/>
<item android:color="@color/colorPrimaryDark"/>
</selector>
3.string 除去相同的语言
defaultConfig{ //只保留指定和默认的资源 resConfigs('zh-rCN') }
4.配置so库
5.移除无用的res资源:


注意先备份res资源数据[不推荐]
6.代码混淆
7.资源压缩 shrinkResources true (作用同5 更好更安全)
8.webp 图片的压缩
9.res资源的混淆