为什么我得到重复的条目:com / google / common / base / FinalizableReference.class?

Mag*_*son 1 android android-studio android-gradle-plugin android-multidex

当我将Microsoft Azure移动服务SDK添加到我的项目中时:

compile 'com.microsoft.azure:azure-mobile-services-android-sdk:2.0.2'
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: com/google/common/base/FinalizableReference.class
Run Code Online (Sandbox Code Playgroud)

可能是什么原因,我该如何解决?
我猜我可以为Gradle制定一些排除规则,但是看起来怎么样?

Raf*_*edo 5

运行任务dependencies,我们可以看到azure-mobile-services-android-sdk包含两个依赖项。

\--- com.microsoft.azure:azure-mobile-services-android-sdk:2.0.2
     +--- com.google.code.gson:gson:2.3
     \--- com.google.guava:guava:18.0
Run Code Online (Sandbox Code Playgroud)

报告为重复的类来自Guava。如果您不直接使用它,则可能是另一个依赖项正在使用它(可能是另一个版本)。对此的可能解决方法是将Guava从依赖项中排除。

compile('com.microsoft.azure:azure-mobile-services-android-sdk:2.0.2') {
    exclude module: 'guava'
}
Run Code Online (Sandbox Code Playgroud)

编辑:

回答您的评论,dependencies在项目中运行任务,然后尝试查找将guava用作依赖项的其他库(可能是较旧的guava版本)。

(in your project root folder)
$ cd app
(if you are running on OSX or Linux)
$ ../gradlew dependencies
(if you are running on Windows)
$ ../gradlew.bat dependencies
Run Code Online (Sandbox Code Playgroud)

当您确定有什么依赖项guava时,以与以前使用azure相同的方式排除它。