通过导入aar作为应用模块,我使用了一个Android库项目。该应用程序在调试模式下编译良好,但当我尝试在发行版中编译时,我会得到以下错误:
Error: Program type already present: com.google.gson.DefaultDateTypeAdapter因此,我在gson的依赖项中进行了研究,发现aar文件中包含了一堆嵌入的jar文件,并且它似乎与我的外部依赖关系相冲突,特别是Retrofit、OkHttp和Gson。

当我导入aar模块时,我试图排除组com.google.code.gson,但是没有运气,它不会改变任何事情:
implementation(project(':ONprintWS')) {
exclude group: 'com.google.code.gson'
}我还以为我可以删除我的build.gradle中的翻新依赖项,看看它们是如何从aar中包含的,但是当我这样做的时候,我的类就找不到retrofit / gson包了。
我已经要求SDK维护者在没有嵌入jar的情况下重新构建SDK (使用传递依赖关系),但这可能有一段时间不会发生,是否存在删除嵌入式jar的方法?
编辑以显示gradle排除,但仍未工作的
//Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation "com.google.code.gson:gson:2.8.5"
implementation("com.squareup.retrofit2:converter-gson:2.4.0") {
exclude group: "com.google.code.gson"
}
implementation "com.squareup.retrofit2:adapter-rxjava2:2.4.0"
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
// ONprintWS SDK
implementation 'io.realm:realm-gradle-plugin:5.3.0'
implementation(project(':ONprintWS')) { // v1.0.4
exclude group: "com.squareup.retrofit2"
exclude group: "com.squareup.okhttp3"
exclude group: "com.google.code.gson"
}发布于 2018-10-26 14:45:38
可以尝试的一件事不是使用exclude,而是为给定的依赖项提供一个resolutionStrategy,例如:
configurations.all {
resolutionStrategy {
force "com.android.support:support-v13:$SUPPORT_LIBRARY_VERSION"
}
}在dependencies部分。这将确保为给定的软件包指定特定版本。
https://stackoverflow.com/questions/53011076
复制相似问题