com.google.gson.ExclusionStrategy 类型定义了多次
Posted
技术标签:
【中文标题】com.google.gson.ExclusionStrategy 类型定义了多次【英文标题】:Type com.google.gson.ExclusionStrategy is defined multiple times 【发布时间】:2020-07-16 05:48:30 【问题描述】:当我尝试向我的应用程序的 gradle 文件中添加 Contentful 的实现时遇到此错误
Type com.google.gson.ExclusionStrategy is defined multiple times
看起来我的中间 dex 文件中的某些内容正在发生。这是完整的错误:
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
以下是我的 gradle 文件。我该如何解决这个问题?
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
【问题讨论】:
【参考方案1】:我也遇到了同样的问题,我猜你应该删除build.gradle文件中的“exclude group: 'com.google.code.gson', module: 'gson', 看看里面的settings.gradle文件项目根目录类似并删除文件....
【讨论】:
【参考方案2】:删除与C/Users/ceddings/StudioProjects/r15-android-rms-kiosk-launcher/kiosk/build/intermediates/mixed_scope_dex_archive/debug/out/1c3715710bef6d11c4bd58c73e056adcb809f2dac72c25d60ee538a9010444f0_1.jar:classes.dex
对应的位置的文件为我解决了这个问题。
【讨论】:
【参考方案3】:以上所有答案都不适合我。
app/build.gradle 配置 all*.exclude module:'gson' //去除重复依赖: gson
这会起作用。
【讨论】:
以上是关于com.google.gson.ExclusionStrategy 类型定义了多次的主要内容,如果未能解决你的问题,请参考以下文章