修复Gradle中的依赖关系解析错误

tyu7yeag  于 2022-11-14  发布在  其他
关注(0)|答案(6)|浏览(173)

当我将okhttp 3依赖从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 article

quhf5bfb

quhf5bfb1#

对于另一个人来说,他们可能会到达这里。如果你使用模块冲突传递依赖,也会发生这种情况。
错误消息片段:
“在模块jetified-javaee-web-api-7.0.jar(javax:javaee-web-api:7.0)和jetified-tyrus-独立客户端-1.14.jar(org.glassfish.tyrus.bundles:tyrus-独立客户端:1.14)中发现重复的类javax.WebSocket.server.服务器端点配置”
在我的例子中,我使用的是Tyrus WebSocket。当我在'libs'文件夹中使用我的另一个库时一切都很好。在将这个库转换为一个模块后,在同一个项目中,我开始收到这个错误。
这是因为我的库使用了'javax:javaee-web-api:7.0',它的包已经在Tyrus中,在主应用程序上。由于库模块将继续需要类,我只是设置'compileOnly'而不是'implementation',阳光再次照耀。我认为将两者结合在一起,在根的'build.gradle'也会工作。

9o685dep

9o685dep2#

你的成绩单上有2个implementation 'androidx.cardview:cardview:1.0.0'
请删除其中一个,然后重新同步。

更新

也删除implementation 'com.intellij:annotations:+@jar'

u3r8eeie

u3r8eeie3#

在您的gradle中使用这条线。

android.enableJetifier=true

gradle.properies

olhwl3o2

olhwl3o24#

在我的例子中,我只是忘记了kapt语法,而不是www.example.com上的实现androidx.room:room-compiler dependency,抛出了一个类似的错误

46qrfjad

46qrfjad5#

  • 构建.gradle*
implementation 'com.intellij:annotations:12.0@jar'
  • 分级属性 *
android.enableJetifier=true
iszxjhcz

iszxjhcz6#

在我的例子中,在注解-java 5和注解之间存在冲突。
这对我很有效:

构建.gradle(:应用程序)

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

相关问题