优化分类
1.性能优化
2.内存优化
3.电量优化
4.网络优化
5.ui优化
ui优化
前提:项目中apk越来越大,ui需要适配手机和平板。
方案:使用svg代替多尺寸png
问题:兼容有问题(5.0以下,9.0以上)
问题处理: https://developer.android.google.cn/studio/write/vector-asset-studio
- 安卓5.0版本之前:
build.gradle 文件中中添加声明
android {
defaultConfig {
//将svg生成指定维度的png图片
vectorDrawables.generatedDensities("xhdpi","xxhdpi");
}
}
}
- 安卓5.0之后
build.gradle 文件中中添加声明
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.2.0'
}
3.安卓x之后
//布局中用法
app:srcCompat=”@drawable/图片名称”
着色器tint
前提:颜色不一样的两个图片,代表两个状态
方案:tint更改图片颜色
只保留指定和默认资源
前提:国内app不需要国际化资源配置
方案:resConfigs(“zh-rCN”,“ko”) //只保留中文
android {
defaultConfig {
resConfigs("zh-rCN","ko") //只保留中文
}
}
}
打包配置
前提:so文件过多
方案:需求不同,类库兼容不同。如只保留:armabi-V7a (有可能兼容armabi)
移除不用资源
Analyze 下 run insepection by name 再输入:unuse res
开启代码压缩
minifyEnable:true //开启代码混淆
压缩资源
shrinkResource:true
资源转换WebP
png转成webp