重复类错误:任务“:app:checkDebugDuplicateClasses”执行失败
Posted
技术标签:
【中文标题】重复类错误:任务“:app:checkDebugDuplicateClasses”执行失败【英文标题】:Duplicate class error: Execution failed for task ':app:checkDebugDuplicateClasses' 【发布时间】:2021-10-09 21:12:05 【问题描述】:我一直在尝试运行我的应用,但出现错误:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
> Duplicate class org.intellij.lang.annotations.Flow found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.intellij.lang.annotations.Identifier found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.intellij.lang.annotations.JdkConstants found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.intellij.lang.annotations.JdkConstants$AdjustableOrientation found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.intellij.lang.annotations.JdkConstants$BoxLayoutAxis found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.intellij.lang.annotations.JdkConstants$CalendarMonth found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.intellij.lang.annotations.JdkConstants$CursorType found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.intellij.lang.annotations.JdkConstants$FlowLayoutAlignment found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.intellij.lang.annotations.JdkConstants$FontStyle found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.intellij.lang.annotations.JdkConstants$HorizontalAlignment found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.intellij.lang.annotations.JdkConstants$InputEventMask found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.intellij.lang.annotations.JdkConstants$ListSelectionMode found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.intellij.lang.annotations.JdkConstants$PatternFlags found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.intellij.lang.annotations.JdkConstants$TabLayoutPolicy found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.intellij.lang.annotations.JdkConstants$TabPlacement found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.intellij.lang.annotations.JdkConstants$TitledBorderJustification found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.intellij.lang.annotations.JdkConstants$TitledBorderTitlePosition found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.intellij.lang.annotations.JdkConstants$TreeSelectionMode found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.intellij.lang.annotations.Language found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.intellij.lang.annotations.MagicConstant found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.intellij.lang.annotations.Pattern found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.intellij.lang.annotations.PrintFormat found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.intellij.lang.annotations.PrintFormatPattern found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.intellij.lang.annotations.RegExp found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.intellij.lang.annotations.Subst found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.jetbrains.annotations.Contract found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.jetbrains.annotations.Nls found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.jetbrains.annotations.NonNls found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.jetbrains.annotations.NotNull found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.jetbrains.annotations.Nullable found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.jetbrains.annotations.PropertyKey found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
Duplicate class org.jetbrains.annotations.TestOnly found in modules jetified-annotations-13.0 (org.jetbrains:annotations:13.0) and jetified-annotations-java5-21.0.1 (org.jetbrains:annotations-java5:21.0.1)
这是我的 build.gradle(Module):
apply plugin: 'com.android.application'
android
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig
applicationId "com.avs.app"
minSdkVersion 24
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildTypes
release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
compileOptions
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
dependencies
implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'
implementation 'com.mikhaellopez:circularimageview:4.3.0'
implementation 'com.loopj.android:android-async-http:1.4.11'
implementation 'cz.msebera.android:httpclient:4.5.8'
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'org.jetbrains:annotations-java5:21.0.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
查看构建错误,我猜它与“implementation 'org.jetbrains:annotations-java5:21.0.1'”有关
Build.gradle(app):
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript
repositories
google()
jcenter()
mavenCentral()
dependencies
classpath 'com.android.tools.build:gradle:4.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
allprojects
repositories
google()
jcenter()
mavenCentral()
task clean(type: Delete)
delete rootProject.buildDir
Gradle-wrapper.properties:
#Thu Mar 12 17:34:37 PST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
Gradle.properties:
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
那么我应该从 build.gradle 中删除“jetbrains-annotations”行吗? 我认为删除它会导致错误。
【问题讨论】:
【参考方案1】:就像我想的那样,解决方案是从 build.gradle 中删除一行:
implementation 'org.jetbrains:annotations-java5:21.0.1'
【讨论】:
【参考方案2】:最近有这个。
注意到你有
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
这是导致此问题的原因。
有关解决方案/解决方法,请参阅此特定评论:
https://github.com/android/android-test/issues/861#issuecomment-872582819
【讨论】:
以上是关于重复类错误:任务“:app:checkDebugDuplicateClasses”执行失败的主要内容,如果未能解决你的问题,请参考以下文章
任务':app:transformClassesWithMultidexlistForDebug'重复Zip条目的执行失败
错误:任务“:app:transformClassesWithJarMergingForDebug”执行失败。 (>TransformException,重复条目)
错误:任务“:app:transformClassesWithJarMergingForDebug”执行失败。 > 重复条目:com/google/android/gms/gcm/Pending