修复 Gradle 中的依赖解析错误

问题描述 投票:0回答:7

当我将 okhttp3 依赖项从 3.4.1 更新到 4.1.0 时,我的项目无法构建并抛出以下错误。

Duplicate class org.intellij.lang.annotations.Identifier found in modules annotations-12.0.jar     
(com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)
Duplicate class org.intellij.lang.annotations.JdkConstants found in modules annotations-12.0.jar     
(com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)
Duplicate class org.intellij.lang.annotations.JdkConstants$AdjustableOrientation found in modules 
annotations-12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar       
(org.jetbrains:annotations:13.0)
Duplicate class org.intellij.lang.annotations.JdkConstants$BoxLayoutAxis found in modules annotations-                              
12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.JdkConstants$CalendarMonth found in modules annotations- 
12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.JdkConstants$CursorType found in modules annotations-   
12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.JdkConstants$FlowLayoutAlignment found in modules        
annotations-12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar  
(org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.JdkConstants$FontStyle found in modules annotations-  
12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.JdkConstants$HorizontalAlignment found in modules   
annotations-12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar 
(org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.JdkConstants$InputEventMask found in modules   
annotations-12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar  
(org.jetbrains:annotations:13.0)
Duplicate class org.intellij.lang.annotations.JdkConstants$ListSelectionMode found in modules  
annotations-12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar  
(org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.JdkConstants$PatternFlags found in modules annotations-
12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.JdkConstants$TabLayoutPolicy found in modules 
annotations-12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar  
(org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.JdkConstants$TabPlacement found in modules annotations-        
12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.JdkConstants$TitledBorderJustification found in modules 
annotations-12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar 
(org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.JdkConstants$TitledBorderTitlePosition found in modules    
annotations-12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)
Duplicate class org.intellij.lang.annotations.JdkConstants$TreeSelectionMode found in modules   
annotations-12.0.jar (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.Language found in modules annotations-12.0.jar 
(com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.MagicConstant found in modules annotations-12.0.jar 
(com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.Pattern found in modules annotations-12.0.jar 
(com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.PrintFormat found in modules annotations-12.0.jar       
(com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

Duplicate class org.intellij.lang.annotations.PrintFormatPattern found in modules annotations-12.0.jar  
(com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

   Duplicate class org.intellij.lang.annotations.RegExp found in modules annotations-12.0.jar     
   (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

   Duplicate class org.intellij.lang.annotations.Subst found in modules annotations-12.0.jar  
   (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

    Duplicate class org.jetbrains.annotations.Nls found in modules annotations-12.0.jar  
    (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

     Duplicate class org.jetbrains.annotations.NonNls found in modules annotations-12.0.jar 
     (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)
     Duplicate class org.jetbrains.annotations.NotNull found in modules annotations-12.0.jar \
    (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)
    Duplicate class org.jetbrains.annotations.Nullable found in modules annotations-12.0.jar 
    (com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)
    Duplicate class org.jetbrains.annotations.PropertyKey found in modules annotations-12.0.jar   
(com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)
Duplicate class org.jetbrains.annotations.TestOnly found in modules annotations-12.0.jar                  
(com.intellij:annotations:12.0) and annotations-13.0.jar (org.jetbrains:annotations:13.0)

    Go to the documentation to learn how to Fix dependency resolution errors.

存在重复依赖项(annotations-12.0.jar 和annotations-13.0.jar)的问题,并且在我的 Gradle 文件中有一个厕所。

 apply plugin: 'com.android.application'

 buildscript {
   repositories {
      mavenCentral()
   }

  dependencies {
   }

 }

repositories {
  mavenCentral()
 }

 android {
signingConfigs {
    release {
        keyAlias 'schoolber'
        keyPassword 'keystore123'
        storeFile file('../publish/keystore.jks')
        storePassword 'keystore123'
    }
    debug {
        keyAlias 'schoolber'
        keyPassword 'keystore123'
        storeFile file('../publish/keystore.jks')
        storePassword 'keystore123'
    }
}
compileSdkVersion rootProject.ext.COMPILE_SDK_VERSION
buildToolsVersion rootProject.ext.TOOLS_VERSION
defaultConfig {
    applicationId "com.schoolberpte.schoober"
    minSdkVersion rootProject.ext.MINIMUM_SDK_VERSION
    targetSdkVersion rootProject.ext.TARGET_SDK_VERSION
    versionCode rootProject.ext.VERSION_CODE
    versionName rootProject.ext.VERSION_NAME
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

    vectorDrawables.useSupportLibrary=true
    multiDexEnabled true
}
applicationVariants.all { variant ->
    variant.resValue "string", "version_name", variant.versionName
    variant.resValue "string", "version_name_string", "Version " + variant.versionName
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        debuggable true
    }
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

dataBinding {
    enabled true
}

packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/CONTRIBUTORS.md'
    exclude 'META-INF/LICENSE.md'
    exclude 'META-INF/MANIKEST.MF'
    exclude 'META-INF/rxjava.properties'
  }

 buildToolsVersion '28.0.3'
 }

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
    exclude group: 'com.android.support', module: 'support-annotations'
})

implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.browser:browser:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
implementation 'io.reactivex.rxjava2:rxjava:2.1.17'
implementation 'com.squareup.retrofit2:retrofit:2.6.0'
implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation 'com.squareup.okhttp3:okhttp:4.1.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'
implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.9.1'
implementation 'com.google.code.gson:gson:2.8.5'
testImplementation 'junit:junit:4.12'
implementation 'uk.co.chrisjenx:calligraphy:2.2.0'
implementation project(':slidingmenu')
implementation 'de.hdodenhof:circleimageview:3.0.0'
implementation files('libs/signalr-client-sdk.jar')
implementation files('libs/signalr-client-sdk-android.jar')
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-places:17.0.0'
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.facebook.android:facebook-android-sdk:4.18.0'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation 'com.facebook.rebound:rebound:0.3.4'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.stripe:stripe-android:4.0.3'
implementation 'com.code-troopers.betterpickers:library:3.0.1'
implementation 'com.google.firebase:firebase-core:17.2.0'
implementation 'com.google.firebase:firebase-messaging:20.0.0'
implementation 'net.danlew:android.joda:2.9.9.1'
implementation('de.keyboardsurfer.android.widget:crouton:1.8.5@aar') {
    exclude group: 'com.google.android', module: 'support-v4'
}
implementation 'me.leolin:ShortcutBadger:1.1.10@aar'
implementation 'com.sothree.slidinguppanel:library:3.4.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.intellij:annotations:+@jar'
implementation 'commons-io:commons-io:2.4'
implementation 'com.google.android.exoplayer:exoplayer:2.10.4'
implementation 'com.github.vipulasri:timelineview:1.1.0'

 }
apply plugin: 'com.google.gms.google-services'

我无法解决此错误,我尝试明确提及注释依赖性,但它并不能解决我的问题,这是我查看的medium文章

android gradle android-gradle-plugin
7个回答
7
投票

对于其他人来说,他们可能会到达这里。如果您使用与传递依赖冲突的模块,也会发生这种情况。

错误消息片段:

“在模块 jetified-javaee-web-api-7.0.jar (javax:javaee-web-api:7.0) 和 jetified-tyrus-standalone-client-1.14.jar (org .glassfish.tyrus.bundles:tyrus-standalone-client:1.14)"

就我而言,我使用的是 Tyrus Websocket。在“libs”文件夹中使用我的另一个库时一切都很好。将此库转换为模块后,在同一个项目中,我开始收到该错误。

这是因为我的库使用了“javax:javaee-web-api:7.0”,它的包已经在主应用程序的 Tyrus 中。由于 lib 模块将继续需要该类,因此我只需设置“compileOnly”而不是“implementation”,然后阳光再次闪耀。我认为将两者合二为一,在 root 的“build.gradle”也可以。


5
投票

您的 gradle 中有 2 个

implementation 'androidx.cardview:cardview:1.0.0'

删除其中之一然后重新同步。

更新

也删除

implementation 'com.intellij:annotations:+@jar'


3
投票

在你的 gradle.properies 中使用这一行

android.enableJetifier=true

gradle.properies


1
投票

就我而言,annotations-java5 和注释之间存在冲突。

这对我有用:

build.gradle(:应用程序)

android {
    ...
    configurations.all {
        exclude group: 'org.jetbrains', module: 'annotations-java5'
    }
}

1
投票

就我而言,我只是忘记了 kapt 语法而不是 androidx.room:room-compiler 依赖项上的实现,引发了类似的错误


0
投票

build.gradle

implementation 'com.intellij:annotations:12.0@jar'

gradle.properties

android.enableJetifier=true

0
投票

问题的原因是

annotations
在2013/2014年从
com.intellij:annotations -> org.jetbrains:annotations
滑过一次组,导致一些依赖项如果没有更新就会引入两个包含相同类的依赖jar,比如都包含一样
org.intellij.lang.annotations.Jdkxxxx
。 解决方案: 检查
com.intellij:annotations
org.jetbrains:annotations
的依赖关系,直接删除或替换为其中之一。推荐使用
org.jetbrains:annotations
如果使用 gradle,解决方案是:

// build.gradle.kts
allprojects {
    project.configurations.all {
        resolutionStrategy {
            eachDependency {
                if (requested.group == "com.intellij" && requested.name == "annotations") {
                    useTarget("org.jetbrains:annotations:23.0.0")
                }
            }
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.