開發筆記-Complie關鍵字過時警告問題
問題描述
之前構建Android專案時,經常出現以下WARNING:
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'. It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
但我檢查了APP專案以及所有的Module,都沒有發現 compile
關鍵字,用全域性搜尋(command + shift + f)也沒有查到,所以應該是某個遠端依賴或外掛中使用了 compile
關鍵字,但如何定位是哪一個呢?
通過IDE Sync
後的提示如下:

Sync後的Warning提示
問題分析和解決
IDE給的提示太簡略,只能通過Gradle命令和 ofollow,noindex">Logging options 來列印詳細的構建資訊來定位問題。Logging級別從簡略到詳細依次為 -q
、 -w
、 -i
、 -d
。IDE預設應該是使用 -q
的,可以逐級列印資訊,也可以直接使用 -d
級別日誌列印資訊。
在專案根目錄下,執行命令
./gradlew assembleDebug -d > gradle.log
其中 -d
是為了列印構建的Debug級別的資訊,非常詳細。由於資訊非常多,命令列介面不能一屏完全顯示,故放入名為 gradle.log
的檔案中。
最後生成的檔案有13M多,5萬多行。通過搜尋關鍵字"WARNING",定位資訊如下:
... 16:03:26.459 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Build operation 'Apply plugin com.sensorsdata.analytics.android to project ':app'' started 16:03:26.459 [WARN] [org.gradle.api.Project] WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'. It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html ...
警告資訊出現在"Build operation Apply plugin com.sensorsdata.analytics.android to project…"語句下,那很可能就是Gradle在應用這個外掛的時候報的錯。
外掛是神策統計的,我的版本是 1.0.2
,檢視官網給的 Mavne庫 ,檢視最新版本, android-gradle-plugin2/
目錄下,最高版本是 2.0.2
。
更新外掛版本,重新構建,警告消失了,問題解決了。