当我添加 UCrop 库版本 2.2.3 和 Cometchat SDK 版本 1.6.+ 时,出现以下错误:
Duplicate class okhttp3.Address found in modules okhttp-3.11.0.jar (com.squareup.okhttp3:okhttp:3.11.0) and okhttp-3.12.0.jar (com.cometchat:pro-android-chat-sdk:1.6.0)
问题是之前提出的问题都没有解决我的问题的答案,因为大多数问题都使用现已弃用的“编译”方法。
我在 stackoverflow 上读到了很多关于同一主题的问题,包括 this , this .
我还尝试从其中一个包中排除 okhttp3 库,以便只使用一个包,使用
implementation('com.github.yalantis:ucrop:2.2.3' )
{
exclude group: 'com.cometchat', module: 'okhttp3'
}
如果有人能向我解释 gradle 中如何排除工作以及我编写的代码有什么问题,我将不胜感激。
最佳答案
不要从 com.cometchat
组中排除 okhttp3
,而是尝试这样做
implementation('com.cometchat:pro-android-chat-sdk:1.6.0') {
configurations {
compile.exclude module: 'okhttp'
}
}
冲突是由于您的 UCrop
和 CometChat
依赖项内部使用 okhttp
库造成的。要解决此问题,您必须排除冲突的库.
Excluding transitive dependency can be done two different ways.
- Exclude transitive dependency by configuration
- Exclude transitive dependency by dependency
要了解有关 gradle dependency
冲突原因和解决方案的更多信息,您可以查看此链接
https://www.concretepage.com/build-tools/gradle/gradle-exclude-transitive-dependency-example
关于android - 添加 uCrop 和 Cometchat 库时 Gradle "Duplicate class"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56513885/