優化分類
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