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

20190410 after putting down Android for a long time, I recently relearned and opened previous projects. I always encountered all kinds of problems, most of which occurred in gradle related details

in the past, due to the upgrade of Android studio and gradle, all kinds of warnings and errors suddenly appeared, which always bothered me

most of the problems have been dealt with before, but they passed after they were solved. There is no record. Now we have to deal with many problems of the same type repeatedly

1. Current environment

Android studio version: 3.4

$ 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)

**I always thought that I was using java 8. Now I know that I have been using java 10 when I record my blog * * upgrade to Java 11 or downgrade to Java 8

$ ./gradlew -v

 ------------------------------------------------------------
 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

2. Wrong

Rebuild failed! The final error prompt is as follows:

	...
	* 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>.

3. Error handling

Check the gradle of Nodule //AndroidUtilCode implementation ‘com.blankj:utilcode:1.21.0’

According to the reference blog, modified the buildTypes section

buildTypes {
    debug {
        minifyEnabled false
        //minifyEnabled true
        //shrinkResources true    //Automatically clean up useless resources
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
    release {
        //minifyEnabled false
        minifyEnabled true
        shrinkResources true    //Automatically clean up useless resources
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}

At the beginning, comment out the debug proguardfiles. It seems to be right once! When I confirm rebuild again, it’s still the same mistake! How can blankj. Utilcode be repeated

according to my own experience, the error may be caused by the backward plug-in version of implementation, which is not suitable for my current as or gradle version, or by the compilation of SDK and API upgrade. The previous gradle setting is like this

 android {
 compileSdkVersion 27
 buildToolsVersion '27.0.3'
 ...

When synchronizing, the following warning will appear:

 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

**Note out buildtoolsversion ‘27.0.3’ according to the warning

 android {
 compileSdkVersion 27
 //buildToolsVersion '27.0.3'
 ...

**You should modify compilesdkversion and the following ‘com. Android. Com’ support:appcompat-v7 : 27.1.1 ‘and so on. Since you are prompted to Android SDK build tools 28.0.3 will be used… when syncing, you can do without changing it

find the repository of this blankj plug-in and see what the latest version is?https://github.com/Blankj/AndroidUtilCode

implementation changed to the latest version 1.23.7

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

rebuild again, OK

4. Postscript: how to find the open source repository of a plug-in

the original project was written by someone else. I don’t know how those plug-ins came from, so my method is very clumsy! Who can tell me what’s the best way

the same is true for many samples downloaded from the Internet, which were one or two years ago, and the plug-ins must not be the latest. If the rebuild fails, you can only find the latest version of the plug-in

Here are my measures:

Implementation ‘com. GitHub. C utta:GifView : 1.1 ‘open directly https://github.com Search for the keyword gifview

Implementation ‘com.scwang.sma like this rtrefresh:SmartRefreshHeader : 1.1.0-alpha-12 ‘, I directly enter the website com.scwang.smartrefresh

Similar Posts: