導(dǎo)致問題原因:是由于設(shè)置shrinkResources true引起的。
在proguard-rules.pro文件中配置此方法是為了刪除無效的Resource。
解決方案:創(chuàng)建res/raw/keep.xml,在keep.xml文件中添加不想被刪除的資源。
1.只有minififyEnable false ? 或者 minififyEnable false ?&& shrinkResources true
資源文件和layout都存在且是有內(nèi)容的
2.只有minifyEnable true
文件大小改變,包變小
資源文件和layout都存在且是有內(nèi)容的
3.minifyEnable true?&& shrinkResources true
資源文件在但是沒有內(nèi)容大小都變成67字節(jié),layout文件內(nèi)容被清空
4.minifyEnable true?&& shrinkResources true 在res/raw/keep.xml(避免被誤刪除)寫了配置的
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
? ? tools:keep="@drawable/bg0,@drawable/bg1"/>
沒有在配置文件中聲明保存的文件沒有內(nèi)容,聲明保存的文件有內(nèi)容(資源文件和layout文件)
注意:string.xml中沒有被引用的怎么設(shè)置都不會被刪除
可以通過gradlew clean assembleRelease - info來獲得APK縮減資源的概覽
當(dāng)您壓縮資源時,Gradle Console 會顯示它從應(yīng)用軟件包中移除的資源的摘要。例如:
:android:shrinkDebugResources
Removed unused resources: Binary resource data reduced from 2570KB to 1711KB: Removed 33%
:android:validateDebugSigning
網(wǎng)搜資料
引用:https://blog.csdn.net/u011889786/article/details/56686492