0

I am getting this confliction error in retrofit:

java.lang.RuntimeException: Duplicate class com.google.gson.DefaultDateTypeAdapter found in modules gson-2.8.5.jar (com.google.code.gson:gson:2.8.5) and pubnub-gson-4.19.0-all.jar (pubnub-gson-4.19.0-all.jar)

Here is my gradle file with all the dependencies :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
//    buildToolsVersion '27.0.3'
//    useLibrary 'org.apache.http.legacy'
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
    }


    defaultConfig {
        applicationId "com.chaufferapplication"
        minSdkVersion 19
        targetSdkVersion 28
        multiDexEnabled true
        versionCode 38
        versionName "4.6.6.0"

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    lintOptions {
        // Returns whether lint should be quiet (for example, not write informational messages such as paths to report files written)
        quiet true

        // Whether lint should set the exit code of the process if errors are found
        abortOnError false

        // Returns whether lint will only check for errors (ignoring warnings)
        ignoreWarnings true

        // Returns whether lint should check for fatal errors during release builds. Default is true.
        // If issues with severity "fatal" are found, the release build is aborted.
        checkReleaseBuilds false
    }
}

dependencies {
    implementation files('libs/json-20140107.jar')
    implementation files('libs/mobiprobe7.0.jar')
    implementation files('libs/pubnub-gson-4.19.0-all.jar'){
        configurations {
            compile.exclude module: 'okhttp3'
        }
    }
    annotationProcessor files('libs/pubnub-gson-4.19.0-all.jar'){
        configurations {
            compile.exclude module: 'okhttp3'
        }
    }
    implementation files('libs/test.jar')
    implementation files('libs/WebSocket.jar')
    implementation 'com.mikhaellopez:circularimageview:3.2.0'
    implementation 'com.google.android.gms:play-services-location:17.0.0'
    implementation 'com.google.android.gms:play-services-places:17.0.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation 'com.google.android.gms:play-services-analytics:17.0.0'
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
    implementation 'com.lsjwzh:materialloadingprogressbar:0.5.8-RELEASE'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'me.zhanghai.android.materialprogressbar:library:1.4.2'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation "se.emilsjolander:stickylistheaders:2.7.0"
    implementation 'me.grantland:autofittextview:0.2.+'
    implementation 'org.droidparts:droidparts:2.9.6'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'me.tankery.lib:circularSeekBar:1.1.7'
    implementation 'ch.acra:acra:4.9.0'
    implementation 'com.google.maps.android:android-maps-utils:0.5+'
    implementation 'androidx.multidex:multidex:2.0.0'
    implementation 'com.googlecode.libphonenumber:libphonenumber:8.2.0'
    implementation 'me.biubiubiu.justifytext:library:1.1'
    implementation 'org.jsoup:jsoup:1.11.3'
    implementation 'com.google.firebase:firebase-core:17.0.1'
    implementation 'com.google.firebase:firebase-messaging:19.0.1'
    implementation 'com.google.firebase:firebase-crash:16.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    //Retrofit
    implementation "com.squareup.retrofit2:retrofit:2.6.1"
   // implementation "com.squareup.retrofit2:converter-gson:2.6.1"
    implementation "com.squareup.retrofit2:converter-scalars:2.6.1"

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

While running the app I am getting an error with retrofit and PubNub confliction. Does anyone have a solution for this? I have tried excluding the okhttp3 as well but still it is not working and throwing error. Retrofit is a dependency and pubnub is a jar file and both have okhttp3 as a common module and conflicting because of having the same module

Kartika Vij
  • 493
  • 2
  • 4
  • 18

3 Answers3

0

add this to implementation("com.squareup.okhttp3:okhttp:4.3.1")app.gradle file and sync project

Edgar
  • 860
  • 1
  • 17
  • 38
  • Same error: java.lang.RuntimeException: Duplicate class com.google.gson.DefaultDateTypeAdapter found in modules gson-2.8.5.jar (com.google.code.gson:gson:2.8.5) and pubnub-gson-4.19.0-all.jar (pubnub-gson-4.19.0-all.jar) – Kartika Vij Feb 03 '20 at 06:22
0

Hi can you try bellow thing maybe help you

implementation ('com.squareup.retrofit2:retrofit:2.6.1') {
        exclude module: 'okhttp'
}
Dhaval Solanki
  • 4,589
  • 1
  • 23
  • 39
0

Have you tried adding a force resolution strategy in your build.gradle?

configurations.all {
    resolutionStrategy.force 'com.squareup.okhttp3:okhttp:4.3.1'
}

Substituting the desired version of okhttp library.

Rai
  • 41
  • 1