I'm trying to use the gcloud-java-datastore library in an Android app project. However, I keep running into the following error when trying to build:
Execution failed for task ':app:transformClassesWithJarMergingForDebug'. com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: ... [one of several different classes]
I've tried excluding various dependencies (e.g. com.google.guava
) from gcloud-java-datastore (v0.2.8) in build.gradle to get it to compile. If I exclude com.google.api.grpc
, com.google.guava
, com.google.api-client
, and one of datastore-v1-protos
or protobuf-java
, I can get it to compile successfully. However, excluding either one of those last two dependencies breaks the core functionality of the library.
Is it even possible to use this library in Android? If so, what am I doing wrong?
Ok, figured it out. I downloaded and extracted datastore-v1-protos-1.0.1.jar, removed everything except the com/google/datastore folder, made a new jar, and included that as a library in my Android Studio project. Then I added the gcloud-java-datastore library to build.gradle with the following exclusions:
compile('com.google.cloud:gcloud-java-datastore:0.2.8') {
exclude group: 'com.google.api-client', module: 'google-api-client-appengine'
exclude group: 'com.google.guava', module: 'guava-jdk5'
exclude group: 'com.google.cloud.datastore', module: 'datastore-v1-protos'
}
and the following packagingOptions:
packagingOptions {
pickFirst 'META-INF/INDEX.LIST'
pickFirst 'META-INF/services/io.grpc.ManagedChannelProvider'
pickFirst 'META-INF/io.netty.versions.properties'
pickFirst 'META-INF/maven/com.google.guava/guava/pom.xml'
pickFirst 'META-INF/maven/com.google.guava/guava/pom.properties'
}