檢測(cè)過(guò)程(注意:使用反射獲取的資源還是會(huì)出現(xiàn)在清單中)
- build文件配置
lintOptions {
//build release 版本 時(shí) 開(kāi)啟lint 檢測(cè)
checkReleaseBuilds true
//lint 遇到 error 時(shí)繼續(xù) 構(gòu)建
abortOnError false
}
2.第三方資源文件過(guò)濾
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:wheel="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="all" <!-- 關(guān)鍵屬性?;蚩捎?tools:ignore="UnUsedResource"-->
android:id="@+id/loading"
android:layout_width="@dimen/alert_width"
android:layout_height="wrap_content"
android:theme="@style/alert_dialog">
</LinearLayout>
- 在 Android Studio 終端選項(xiàng)下 執(zhí)行 命令
gradle lint
在 yoru_project_dirctory/build/outputs/ 會(huì)生成 兩個(gè)文件 lint-result.xml, lint-result.html 和文件夾 lint-result-files. 最重要的是 lint-result.xml 文件,里面包含了我們要解析的信息,包含項(xiàng)目中不再使用的資源文件信息。
4.執(zhí)行 命令
android-resource-remover --xml lint-result.xml
執(zhí)行完這個(gè)命令,項(xiàng)目中除第三方資源外不再使用的資源文件,包含 string ,color ,value等,全都被刪除掉