2

I'm getting this error when I try to add an implementation to my app's gradle file for Contentful

Type com.google.gson.ExclusionStrategy is defined multiple times

It looks like something in my intermediate dex file is going on. Here's the full error:

Error: /Users/ceddings/StudioProjects/r15-android-rms-kiosk-launcher/kiosk/build/intermediates/mixed_scope_dex_archive/debug/out/2fcf9ca3ebe4bba6e5de15039706dbd823b837def40fd130c6d32dbf72d7d3fe_1.jar:classes.dex, Type com.google.gson.ExclusionStrategy is defined multiple times: /Users/ceddings/StudioProjects/r15-android-rms-kiosk-launcher/kiosk/build/intermediates/mixed_scope_dex_archive/debug/out/2fcf9ca3ebe4bba6e5de15039706dbd823b837def40fd130c6d32dbf72d7d3fe_1.jar:classes.dex, /Users/ceddings/StudioProjects/r15-android-rms-kiosk-launcher/kiosk/build/intermediates/mixed_scope_dex_archive/debug/out/1c3715710bef6d11c4bd58c73e056adcb809f2dac72c25d60ee538a9010444f0_1.jar:classes.dex

Below is my gradle file. How do I resolve this issue?

dependencies {
implementation project(':sharedcore')
implementation project(':data')
implementation project(':scanner')

implementation deps.kotlin.kotlin_jre
implementation deps.android.app_compat
implementation deps.android.material
implementation deps.android.constraint_layout
implementation deps.logging.timber
implementation deps.retrofit.retrofit
implementation deps.retrofit.retrofit_moshi
implementation deps.moshi.moshi
implementation deps.koin.koin_viewmodel
implementation deps.kotlin.coroutines_core
implementation deps.kotlin.coroutines_android
implementation(deps.auth.adal) {
    exclude group: 'com.android.support', module: 'appcompat-v7'
    exclude group: 'com.google.code.gson', module: 'gson'
}
implementation deps.ms_app_center.analytics
implementation deps.ms_app_center.crashes
implementation deps.viewpager2.viewpager2
implementation deps.contentful.contentful

// Testing
testImplementation deps.testing.junit
testImplementation deps.testing.test_core
testImplementation deps.testing.test_runner
testImplementation deps.testing.test_rules
testImplementation deps.testing.ext_junit
testImplementation deps.testing.mockk
testImplementation deps.testing.mockk_android
testImplementation deps.testing.robolectric
testImplementation deps.testing.espresso_core
testImplementation deps.testing.espresso_intents

}

Cody
  • 1,801
  • 3
  • 28
  • 53

4 Answers4

2
configurations {
    implementation.exclude module: 'gson' //Remove duplicate dependencies: gson
}
Sergio
  • 2,346
  • 2
  • 24
  • 28
1

All above answers did not work for me.

app/build.gradle configurations{ all*.exclude module:'gson' //Remove duplicate dependencies: gson }

This will work.

sudhanshu
  • 409
  • 1
  • 5
  • 12
0

I also encountered the same problem, I guess you should delete "exclude group: 'com.google.code.gson', module: 'gson' in the build.gradle file, and look at the settings.gradle file in the project root directory similar And delete the file....

0

Deleting the file at location corresponding to C/Users/ceddings/StudioProjects/r15-android-rms-kiosk-launcher/kiosk/build/intermediates/mixed_scope_dex_archive/debug/out/1c3715710bef6d11c4bd58c73e056adcb809f2dac72c25d60ee538a9010444f0_1.jar:classes.dex solved the issue for me.

Usman Zafer
  • 1,261
  • 1
  • 10
  • 15