android - 添加 uCrop 和 Cometchat 库时 Gradle "Duplicate class"错误

标签 android gradle

当我添加 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'
        }
    }

冲突是由于您的 UCropCometChat 依赖项内部使用 okhttp 库造成的。要解决此问题,您必须排除冲突的库.

Excluding transitive dependency can be done two different ways.

  1. Exclude transitive dependency by configuration
  2. 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/

相关文章:

android - 从服务中获取当前 fragment

android - 超大屏幕分辨率的 AVD 设置

Android NDK JNI数组引用表溢出

jenkins - 从控制台读取时在Jenkins中超时

android - 资源链接失败,错误 : resource android:attr/dialogCornerRadius not found

gradle - Gradle String索引超出范围:0

java - 如何从Java/Android中自动获取笔记本电脑的IP地址

android - 创建所有应用程序源的zip文件,不包括构建文件

安卓 : How can I implement user manual or app instruction on start up of app

java - Gradle找不到tools.jar