Android - OkHttp 3.6.0 Adress.class 重复

Android - OkHttp 3.6.0 Adress.class Duplication

我遇到过类似的问题,表明存在同样的问题。但是,就我而言,它似乎以不同的方式发生,不应产生如下所述的问题:

假设我有两个内部私有库,发布在私有 Maven 存储库中,名称如下:

com.x.y.analytics
com.x.y.player

这两个库都使用 OkHttp 3.6.0 和下面给定的代码片段:

provided 'com.squareup.okhttp3:okhttp:3.6.0'

所以基本上,当我向 maven 发布 aar 时,我不包括实际的库,我编译它并使用下面的代码片段将它提供给父项目中提到的库:

compile 'com.squareup.okhttp3:okhttp:3.6.0'

但是,尽管由于该库只有 1 个编译版本而一切都应该没问题,但我还是出现了以下错误:

Error:Execution failed for task ':application:transformClassesWithJarMergingForDebug'.

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: okhttp3/Address.class

我相信如果我使用 compile 将库注入私有库中,就会发生这个问题,但由于我使用了 provided,如果有任何解决方法,你能详细说明这个问题吗?

PS: OkHttp 的 GitHub 项目也有一个问题可以找到 here.

我遇到了同样的问题。我试着添加这一行

android {
configurations {
all*.exclude group: 'com.squareup.okhttp3', module: 'okhttp'
}
}

而且它对我来说很好用。请努力做到。