android Studio 版本 : 3.4java
$ java -version java version "10.0.2" 2018-07-17 Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13) Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)android
** 一直覺得本身使用的是 java 8 ,此刻記錄博客時才知道一直使用的是 java 10 ** 回頭升級到 java 11 或者降級到 java 8git
$ ./gradlew -vgithub
------------------------------------------------------------ Gradle 5.1.1 ------------------------------------------------------------ Build time: 2019-01-10 23:05:02 UTC Revision: 3c9abb645fb83932c44e8610642393ad62116807 Kotlin DSL: 1.1.1 Kotlin: 1.3.11 Groovy: 2.5.4 Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018 JVM: 10.0.2 ("Oracle Corporation" 10.0.2+13) OS: Mac OS X 10.14.4 x86_64
rebuild 失敗! 最後錯誤提示部分以下 app
... * What went wrong: Execution failed for task ':app:checkDebugDuplicateClasses'. > 1 exception was raised by workers: java.lang.RuntimeException: Duplicate class com.blankj.utilcode.BuildConfig found in modules classes.jar (com.blankj:bus:1.0) and classes.jar (com.blankj:utilcode:1.21.0) Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.
參考 https://blog.csdn.net/willhanweijia/article/details/87250386學習
檢查 Nodule 的 gradle //AndroidUtilCode implementation 'com.blankj:utilcode:1.21.0'gradle
按照參考博客,修改了 buildTypes 部分ui
buildTypes { debug { minifyEnabled false //minifyEnabled true //shrinkResources true //自動清理無用資源 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } release { //minifyEnabled false minifyEnabled true shrinkResources true //自動清理無用資源 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } }
剛開始註釋掉 debug 的 proguardFiles ,好像對了一次!等我確認再次 rebuild 的時候,仍是寶同樣的錯誤!blankj.utilcode 怎麼又重複了呢?this
根據我本身的經驗,錯誤緣由多是 implementation 的插件版本落後了,不適合我當前的 AS 或 gradle 版本,或者是編譯 SDK、API 升級形成的 以前 gradle 設置是這樣的spa
android { compileSdkVersion 27 buildToolsVersion '27.0.3' ...
同步的時候,會出現如下警告:
CONFIGURE SUCCESSFUL in 1s WARNING: The specified Android SDK Build Tools version (27.0.3) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.4.0. Android SDK Build Tools 28.0.3 will be used. To suppress this warning, remove "buildToolsVersion '27.0.3'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools. Remove Build Tools version and sync project Affected Modules: app
** 按照警告提示,註釋掉 buildToolsVersion '27.0.3' !
android { compileSdkVersion 27 //buildToolsVersion '27.0.3' ...
** 應該直接修改 compileSdkVersion 以及後面的 'com.android.support:appcompat-v7:27.1.1' 等,既然 sync 的時候提示 Android SDK Build Tools 28.0.3 will be used ... 因此不改也能夠!
找到這個 Blankj 插件的倉庫,看看最新版本是多少? https://github.com/Blankj/AndroidUtilCode
implementation 改爲最新版 1.23.7
//AndroidUtilCode implementation 'com.blankj:utilcode:1.23.7'
再次 rebuild ,ok了!
原始項目是別人寫的,我不知道那些插件他最初怎麼來的,因此個人方法很笨拙!誰能告訴我有什麼好辦法?
網上下載的不少sample 也是這樣的,都是一兩年以前的,其中的插件必定不是最新的,若是遇到 rebuild 不過去,只能去查找插件的最近版本
如下是個人本辦法: