Reputation: 28325
When I add the Microsoft Azure Mobile Services SDK to my project:
compile 'com.microsoft.azure:azure-mobile-services-android-sdk:2.0.2'
I get this error:
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
What could be the reason and how do I solve this?
I'm guessing I could make some exclude rule for Gradle, but how would that look like?
Upvotes: 1
Views: 1863
Reputation: 76536
it;s because you have two libraries that include the same java class. the command gradle dependencies
should tell you what it is.
And you have a few choices of how to exclude a dependency:
dependencies {
compile('com.microsoft.azure:azure-mobile-services-android-sdk:2.0.2') {
exclude module: 'cglib' //by artifact name
exclude group: 'org.jmock' //by group
exclude group: 'com.unwanted', module: 'someLib' //by both name and group
}
}
Upvotes: 1
Reputation: 5659
Running the task dependencies
, we can see that the azure-mobile-services-android-sdk
contains two dependencies.
\--- com.microsoft.azure:azure-mobile-services-android-sdk:2.0.2
+--- com.google.code.gson:gson:2.3
\--- com.google.guava:guava:18.0
The class reported as duplicate is from Guava
. If you are not using it directly, probably another dependency is using it (probably with another version). A possibly fix for this is to exclude Guava from the dependency.
compile('com.microsoft.azure:azure-mobile-services-android-sdk:2.0.2') {
exclude module: 'guava'
}
Edit:
Answering your comment, run the dependencies
task in your project and try to find the other library that is using guava as a dependency (probably an older version of 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
When you figure what dependency have guava
, exclude it in the same way you did with azure before.
Upvotes: 5