Duplicate class com.blankj.utilcode.BuildConfig found in modules classes.jar

20190410 放下 android 好久以後,最近又從新學習,打開之前的項目,老是遇到各類問題,大部分發生在 gradle 相關細節

過去好好地項目,因爲 Android Studio 升級,gradle 升級,忽然出現各類警告、錯誤,老是很心煩的!

大部分問題之前也都處理過,當時解決完就過去了,沒有記錄,如今不得不重複處理好多相同類型的問題

一、當前環境

  1. android Studio 版本 : 3.4java

  2. $ 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

  1. $ ./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>.

三、 錯誤處理

  1. 參考 https://blog.csdn.net/willhanweijia/article/details/87250386學習

  2. 檢查 Nodule 的 gradle //AndroidUtilCode implementation 'com.blankj:utilcode:1.21.0'gradle

  3. 按照參考博客,修改了 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

  4. 根據我本身的經驗,錯誤緣由多是 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 ... 因此不改也能夠!

  5. 找到這個 Blankj 插件的倉庫,看看最新版本是多少? https://github.com/Blankj/AndroidUtilCode

  6. implementation 改爲最新版 1.23.7

    //AndroidUtilCode
     implementation 'com.blankj:utilcode:1.23.7'

    再次 rebuild ,ok了!

四、 後記:怎麼查找某個插件的開源倉庫?

原始項目是別人寫的,我不知道那些插件他最初怎麼來的,因此個人方法很笨拙!誰能告訴我有什麼好辦法?

網上下載的不少sample 也是這樣的,都是一兩年以前的,其中的插件必定不是最新的,若是遇到 rebuild 不過去,只能去查找插件的最近版本

如下是個人本辦法:

  1. 像這種 implementation 'com.github.Cutta:GifView:1.1' 直接打開https://github.com 去搜索 關鍵字 GifView
  2. 像這種 implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0-alpha-12' 的,我就直接輸入 網址 com.scwang.smartrefresh ,通常都是百度出來的
相關文章
相關標籤/搜索