0

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?

user58094
  • 53
  • 3
  • Are you trying to use App Engine? I think you're looking for Endpoints. https://cloud.google.com/appengine/docs/java/endpoints/helloendpoints-android-studio – OneCricketeer Aug 31 '16 at 03:31
  • @cricket_007 No, not using App Engine. I'm aware of Endpoints, but it is unnecessary for my project. I had a working solution with the old Google Cloud Datastore API v1beta2 Client Library for Java, but that won't work anymore once v1beta2 is deprecated at the end of September. – user58094 Aug 31 '16 at 03:45
  • I see. Sorry, endpoints is the only android lib I've used to connect to the datastore. If all else fails, I guess there's a REST API – OneCricketeer Aug 31 '16 at 04:05

1 Answers1

0

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'
}
user58094
  • 53
  • 3