Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fix dependency resolution errors in Gradle

When I update the okhttp3 dependence from 3.4.1 to 4.1.0, my project fails to build and throws following errors.

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.

There is the issue of duplicate dependencies (annotations-12.0.jar and annotations-13.0.jar) and have a loo into my Gradle file.

 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'

I am unable to resolve this error, I have tried to explicitly menttion the annotations dependency but it dose not solve my issue, here is the medium article which I looked at.

like image 280
Abdul Rahman Shamair Avatar asked Sep 19 '19 14:09

Abdul Rahman Shamair


People also ask

How do I resolve Gradle dependencies?

Obtaining module metadata Given a required dependency, with a version, Gradle attempts to resolve the dependency by searching for the module the dependency points at. Each repository is inspected in order. Depending on the type of repository, Gradle looks for metadata files describing the module ( .

How do you resolve transitive dependencies in Gradle?

A variant of a component can have dependencies on other modules to work properly, so-called transitive dependencies. Releases of a module hosted on a repository can provide metadata to declare those transitive dependencies. By default, Gradle resolves transitive dependencies automatically.


Video Answer


3 Answers

For another ones, who maybe reach here. It happens also if you use modules clashing transitive dependency(ies).

Snippet of error message:

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

In my case, i was using Tyrus Websocket. Everything was fine while using another library of mine in 'libs' folder. After converting this library to a module, in the same project, I started receiving that error.

It was because my lib utilizes 'javax:javaee-web-api:7.0' which has packages that are already in Tyrus, on the main App. As the lib module would keep needing the class, i just set 'compileOnly' instead of 'implementation' and the sun shined again. I think joining both in one, at root's 'build.gradle' would also work.

like image 173
Luís Alves Avatar answered Oct 17 '22 21:10

Luís Alves


You have 2 of implementation 'androidx.cardview:cardview:1.0.0' in your gradle.
Delete one of them then re-sync.

UPDATE

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

like image 29
Jagar Avatar answered Oct 17 '22 21:10

Jagar


use this line in your gradle.properies

android.enableJetifier=true

gradle.properies

like image 2
kali m Avatar answered Oct 17 '22 22:10

kali m