Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compiling google cloud service client library with guava

I'm using android studio. I'm developing an app with google cloud appengine (endpoints) and google cloud storage. When I write the gradle dependencies as shown:

dependencies {
    compile 'com.google.apis:google-api-services-storage:v1beta2-rev77-1.20.0'
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:multidex:1.0.1'
    compile project(path: ':backend', configuration: 'android-endpoints')


    compile files('libs/joda-time-2.8.2.jar')
    compile ('com.google.appengine.tools:appengine-gcs-client:0.4.4')
    compile files('libs/guava-18.0.jar')
}

I retrieve an error when compiling:

Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
 java.util.zip.ZipException: duplicate entry: com/google/common/reflect/TypeToken$TypeCollector$ForwardingTypeCollector.class

I've tried to exclue in this way

compile ('com.google.appengine.tools:appengine-gcs-client:0.4.4'){
    exclude group: 'com.google.guava'
}

But nothing works. Can anybody help me?

like image 447
Rubén Avendaño Caballero Avatar asked Aug 10 '26 02:08

Rubén Avendaño Caballero


1 Answers

1) First of all let's remove this ugly jars from your dependencies. I am about joda-time and guava

compile 'joda-time:joda-time:2.8.2'  
compile 'com.google.guava:guava:18.0'     

2) Move exclude group: 'com.google.guava' from appengine to apis

compile ('com.google.apis:google-api-services-storage:v1beta2-rev77-1.20.0') {
        exclude group: 'com.google.guava'
}

And add it to your :backend

compile (project(path: ':backend', configuration: 'android-endpoints')) {
    exclude group: 'com.google.guava'
}

3) Now you can get this error com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '...java'' finished with non-zero exit value 1
If yes we should add exclude to appengine

compile('com.google.appengine.tools:appengine-gcs-client:0.4.4') {
    exclude group: 'javax.transaction'
}

4) Now you get Duplicate files copied in APK META-INF/NOTICE.txt
And this we solve with packagingOptions in android {} section

packagingOptions {
        exclude 'META-INF/NOTICE.txt'
}

So your final result

android {
    ...
    packagingOptions {
        exclude 'META-INF/NOTICE.txt'
    }
}
dependencies {
    compile (project(path: ':backend', configuration: 'android-endpoints')) {
        exclude group: 'com.google.guava'
    }

    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:multidex:1.0.1'

    compile 'joda-time:joda-time:2.8.2'
    compile 'com.google.guava:guava:18.0'

    compile ('com.google.apis:google-api-services-storage:v1beta2-rev77-1.20.0') {
        exclude group: 'com.google.guava'
    }
    compile('com.google.appengine.tools:appengine-gcs-client:0.4.4') {
        exclude group: 'javax.transaction'
    }
}
like image 148
Stas Parshin Avatar answered Aug 12 '26 17:08

Stas Parshin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!