android - 修复 Gradle 中的依赖解析错误

标签 android gradle android-gradle-plugin

当我将 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 article我看着。

最佳答案

对于可能到达这里的其他人。如果您使用与传递依赖项冲突的模块,也会发生这种情况。
错误信息 fragment :

"Duplicate class javax.websocket.server.ServerEndpointConfig found in modules jetified-javaee-web-api-7.0.jar (javax:javaee-web-api:7.0) and 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”,然后阳光再次闪耀。我认为将两者合二为一,根目录的“build.gradle”也可以。

关于android - 修复 Gradle 中的依赖解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58013128/

相关文章:

Android,如何测量耗时

安卓硬件调试

android - 是否可以使用 junit 测试来测试本地值?

android - 哪些文件包含 Android Studio 2.2 的项目设置?

android - Gradle Android Buildscript Configuration with Flavors

android - 如何动态地将 View 添加到 ViewGroup 并与其子项之一垂直对齐

android - 从 Gradle 中的 Url 编译 Jar

android - Android Gradle构建无法添加第三方库

c++ - 链接外部共享库android ndk

android - 如何为特定CPU架构创建apk文件