31

This started when I added google-api-services-calendar. I am getting this error when trying to build:

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
     com.android.build.transform.api.TransformException: java.util.zip.ZipException: 
     duplicate entry: com/google/common/annotations/Beta.class

This is part of the output when running ./gradlew app:dependencies:

compile - Classpath for compiling the main sources.
+--- com.google.android.gms:play-services-measurement:8.1.0
|    +--- com.google.android.gms:play-services-base:8.1.0
|    |    \--- com.google.android.gms:play-services-basement:8.1.0
|    |         \--- com.android.support:support-v4:22.2.0 -> 23.0.1
|    |              \--- com.android.support:support-annotations:23.0.1
|    \--- com.google.android.gms:play-services-analytics:8.1.0
|         +--- com.google.android.gms:play-services-basement:8.1.0 (*)
|         \--- com.google.android.gms:play-services-ads:8.1.0
|              +--- com.google.android.gms:play-services-basement:8.1.0 (*)
|              \--- com.google.android.gms:play-services-appindexing:8.1.0
|                   \--- com.google.android.gms:play-services-basement:8.1.0 (*)
+--- com.google.dagger:dagger:2.0
|    \--- javax.inject:javax.inject:1
+--- com.google.android.gms:play-services-identity:8.1.0
|    \--- com.google.android.gms:play-services-base:8.1.0 (*)
+--- com.google.android.gms:play-services-plus:8.1.0
|    \--- com.google.android.gms:play-services-base:8.1.0 (*)
+--- com.google.android.gms:play-services:8.1.0
|    +--- com.google.android.gms:play-services-ads:8.1.0 (*)
|    +--- com.google.android.gms:play-services-analytics:8.1.0 (*)
|    +--- com.google.android.gms:play-services-appindexing:8.1.0 (*)
|    +--- com.google.android.gms:play-services-appinvite:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-appstate:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-basement:8.1.0 (*)
|    +--- com.google.android.gms:play-services-cast:8.1.0
|    |    +--- com.google.android.gms:play-services-base:8.1.0 (*)
|    |    \--- com.android.support:mediarouter-v7:22.2.0
|    |         \--- com.android.support:appcompat-v7:22.2.0 -> 23.0.1
|    |              \--- com.android.support:support-v4:23.0.1 (*)
|    +--- com.google.android.gms:play-services-drive:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-fitness:8.1.0
|    |    +--- com.google.android.gms:play-services-base:8.1.0 (*)
|    |    \--- com.google.android.gms:play-services-location:8.1.0
|    |         +--- com.google.android.gms:play-services-base:8.1.0 (*)
|    |         \--- com.google.android.gms:play-services-maps:8.1.0
|    |              \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-games:8.1.0
|    |    +--- com.google.android.gms:play-services-base:8.1.0 (*)
|    |    \--- com.google.android.gms:play-services-drive:8.1.0 (*)
|    +--- com.google.android.gms:play-services-gcm:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-identity:8.1.0 (*)
|    +--- com.google.android.gms:play-services-location:8.1.0 (*)
|    +--- com.google.android.gms:play-services-maps:8.1.0 (*)
|    +--- com.google.android.gms:play-services-measurement:8.1.0 (*)
|    +--- com.google.android.gms:play-services-nearby:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-panorama:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-plus:8.1.0 (*)
|    +--- com.google.android.gms:play-services-safetynet:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-vision:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-wallet:8.1.0
|    |    +--- com.google.android.gms:play-services-base:8.1.0 (*)
|    |    +--- com.google.android.gms:play-services-identity:8.1.0 (*)
|    |    \--- com.google.android.gms:play-services-maps:8.1.0 (*)
|    \--- com.google.android.gms:play-services-wearable:8.1.0
|         \--- com.google.android.gms:play-services-base:8.1.0 (*)
+--- com.google.guava:guava:18.0
+--- com.google.maps.android:android-maps-utils:0.4
+--- com.google.apis:google-api-services-calendar:v3-rev125-1.20.0
|    \--- com.google.api-client:google-api-client:1.20.0
|         +--- com.google.oauth-client:google-oauth-client:1.20.0
|         |    +--- com.google.http-client:google-http-client:1.20.0
|         |    |    \--- com.google.code.findbugs:jsr305:1.3.9
|         |    \--- com.google.code.findbugs:jsr305:1.3.9
|         +--- com.google.http-client:google-http-client-jackson2:1.20.0
|         |    +--- com.google.http-client:google-http-client:1.20.0 (*)
|         |    \--- com.fasterxml.jackson.core:jackson-core:2.1.3 -> 2.2.2
|         \--- com.google.guava:guava-jdk5:13.0
+--- com.android.support:design:23.0.1
|    +--- com.android.support:support-v4:23.0.1 (*)
|    \--- com.android.support:appcompat-v7:23.0.1 (*)
+--- com.android.support:recyclerview-v7:23.0.1
|    +--- com.android.support:support-v4:23.0.1 (*)
|    \--- com.android.support:support-annotations:23.0.1
+--- com.android.support:cardview-v7:23.0.1
+--- com.android.support:palette-v7:23.0.1
|    \--- com.android.support:support-v4:23.0.1 (*)
+--- com.android.support:appcompat-v7:22.2.0 -> 23.0.1 (*)
+--- com.android.support:support-v4:22.2.0 -> 23.0.1 (*)
+--- com.firebase:firebase-client-android:2.3.1
|    \--- com.firebase:firebase-client-jvm:2.3.1
|         +--- com.fasterxml.jackson.core:jackson-databind:2.2.2
|         |    +--- com.fasterxml.jackson.core:jackson-annotations:2.2.2
|         |    \--- com.fasterxml.jackson.core:jackson-core:2.2.2
|         \--- com.firebase:tubesock:0.0.11
+--- com.firebase:firebase-client-jvm:2.3.0 -> 2.3.1 (*)
+--- net.danlew:android.joda:2.8.0
|    \--- joda-time:joda-time:2.8
+--- org.joda:joda-convert:1.2
+--- com.squareup:otto:1.3.5
+--- com.jakewharton:butterknife:7.0.1
+--- org.apache.commons:commons-lang3:3.4
+--- org.apache.commons:commons-collections4:4.0
\--- com.bignerdranch.android:expandablerecyclerview:1.0.3
     \--- com.android.support:recyclerview-v7:22.2.0 -> 23.0.1 (*)

I have tried adding this to all my dependencies:

compile (some.dependencie.that.may.or.may.not.have.the.duplicate){
    exclude group: 'com.google.common', module: 'annotations'
}

I tried adding this to my android block:

configurations {
   all*.exclude group: 'com.google.common', module: 'annotations'
}    

with these variations:

 all*.exclude module: 'annotations`
 all*.exclude group: 'com.google.common'
 all*.exclude group: 'com.google.common.annotations'

This is the build.gradle before any attempts to fix error:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    // Google
    compile 'com.google.dagger:dagger:2.0'
    apt 'com.google.dagger:dagger-compiler:2.0'
    compile 'com.google.android.gms:play-services-identity:8.1.0'
    compile 'com.google.android.gms:play-services-plus:8.1.0'
    compile 'com.google.android.gms:play-services:8.1.0'
    compile 'com.google.guava:guava:18.0'
    compile 'com.google.maps.android:android-maps-utils:0.4'
    compile('com.google.apis:google-api-services-calendar:v3-rev125-1.20.0') {
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    }

    // Android Design
    compile 'com.android.support:design:23.0.1'
    compile 'com.android.support:recyclerview-v7:23.0.1'
    compile 'com.android.support:cardview-v7:23.0.1'
    compile 'com.android.support:palette-v7:23.0.1'

    // Android Support
    compile('com.android.support:appcompat-v7:22.2.0') {
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    }
    compile('com.android.support:support-v4:22.2.0') {
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    }

    // Firebase
    compile('com.firebase:firebase-client-android:2.3.1') {
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    }
    compile('com.firebase:firebase-client-jvm:2.3.0') {
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    }

    // Joda Time
    compile 'net.danlew:android.joda:2.8.0'
    compile 'org.joda:joda-convert:1.2'

    // Square
    compile 'com.squareup:otto:1.3.5'
    compile 'com.jakewharton:butterknife:7.0.1'
    provided 'javax.annotation:jsr250-api:1.0'

    // Common
    compile 'org.apache.commons:commons-lang3:3.4'
    compile 'org.apache.commons:commons-collections4:4.0'

    compile 'com.bignerdranch.android:expandablerecyclerview:1.0.3'
}

I have searched my project for Beta.class and found that it is only being used in some jars; com.google.common.annotations, com.google.api.client.util and dagger.internal. I tried to add the exclude group to those related dependencies and still see the same error.

I have been stuck here for way too long. Any suggestions?

Chad Bingham
  • 32,650
  • 19
  • 86
  • 115
  • 3
    I just faced this problem when updating the Android Gradle plugin to com.android.tools.build:gradle:1.4.0-beta3. In my case, the problem is due to AndroidSlidingUpPanelLayout, which depends in turn on nineoldandroids ([link](https://github.com/umano/AndroidSlidingUpPanel/search?utf8=%E2%9C%93&q=nineoldandroids)), and it produces the error. I "fixed" it going back to com.android.tools.build:gradle:1.3.0. – Roi Oct 01 '15 at 09:33
  • I am still on 1.3.0 and havent changed since it came out. – Chad Bingham Oct 03 '15 at 17:38
  • @ChadBingham Can you try to also exclude `com.google.guava:guava-jdk5:13.0` module; And then, run the task again? – kucing_terbang Oct 07 '15 at 07:38
  • @kucing_terbang expand on that, exclude guava from what module? or exclude what from guava? – Chad Bingham Oct 07 '15 at 18:44
  • @ChadBingham from `google-api-services-calendar` module. – kucing_terbang Oct 08 '15 at 04:34
  • Hi @ChadBingham I've tried to compile sample project with your dependencies list and it works fine on 'com.android.tools.build:gradle:1.4.0-beta3' and 'com.android.tools.build:gradle:1.3.0'. I even don't have app:transformClassesWithJarMergingForDebug task in gradle build tasks. It seems that problem in you build.gradle file. Have you tried to build simple project just with these dependencies? – Oleksandr Oct 08 '15 at 10:19
  • @Alexandr yes i tried it in a different project and it worked, UNTIL I added manifest permissions for google Calendar API. then I say the same error. – Chad Bingham Oct 10 '15 at 19:59
  • @kucing_terbang i tried this and saw the same error. – Chad Bingham Oct 10 '15 at 19:59
  • Check out my answer [here](http://stackoverflow.com/a/40938643/2107661) to resolve this error in general. – b00n12 Dec 02 '16 at 18:25

3 Answers3

24

Exclude group: 'com.google.guava' from play services related dependencies.

For example:

compile ('com.google.android.gms:play-services:8.1.0'){
    exclude group: 'com.google.guava'
}

P.S. Before getting your error I've faced with a lot of different, so my final dependencies list is:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    // Google
    compile 'com.google.dagger:dagger:2.0'
    apt 'com.google.dagger:dagger-compiler:2.0'
    compile ('com.google.android.gms:play-services-identity:8.1.0'){
        exclude group: 'com.google.guava'
    }
    compile ('com.google.android.gms:play-services-plus:8.1.0'){
        exclude group: 'com.google.guava'
    }
    compile ('com.google.android.gms:play-services:8.1.0'){
        exclude group: 'com.google.guava'
    }
    compile 'com.google.guava:guava:18.0'
    compile 'com.google.maps.android:android-maps-utils:0.4'

    compile('com.google.apis:google-api-services-calendar:v3-rev125-1.20.0') {
        exclude group: 'org.apache.httpcomponents'
        exclude group: 'com.android.support'
        exclude module: 'support-annotations'
        exclude group: 'com.google.guava'
    }

    // Android Design
    compile ('com.android.support:design:23.0.1'){
        exclude group: 'com.android.support'
    }
    compile ('com.android.support:recyclerview-v7:23.0.1') {
        exclude group: 'com.android.support'
    }

    compile 'com.android.support:cardview-v7:23.0.1'
    compile ('com.android.support:palette-v7:23.0.1'){
        exclude group: 'com.android.support'
    }

    // Android Support
    compile('com.android.support:appcompat-v7:22.2.0') {
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
        exclude group: 'com.android.support'
    }

    compile 'com.android.support:support-annotations:23.0.1'
    compile('com.android.support:support-v4:22.2.0') {
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
        exclude module: 'support-annotations'
    }

    // Firebase
    compile('com.firebase:firebase-client-android:2.3.1') {
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    }
    compile('com.firebase:firebase-client-jvm:2.3.0') {
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    }

    // Joda Time
    compile 'net.danlew:android.joda:2.8.0'
    compile 'org.joda:joda-convert:1.2'

    // Square
    compile 'com.squareup:otto:1.3.5'
    compile 'com.jakewharton:butterknife:7.0.1'
    provided 'javax.annotation:jsr250-api:1.0'

    // Common
    compile 'org.apache.commons:commons-lang3:3.4'
    compile 'org.apache.commons:commons-collections4:4.0'

    compile ('com.bignerdranch.android:expandablerecyclerview:1.0.3'){
        exclude group: 'com.android.support'
    }
}
Oleksandr
  • 6,226
  • 1
  • 46
  • 54
  • 2
    Why was **guava** specifically the one that needed to be excluded? – IgorGanapolsky Jul 21 '16 at 17:04
  • @IgorGanapolsky, I've tried to exclude guava intuitively. And guava was really a problem. I have no clue why... – Oleksandr Jul 22 '16 at 13:14
  • I've the same problem. I have used the same library in `libs` folder as well as in gradle dependency. I removed in one place and problem is gone. – Akbarsha Sep 20 '16 at 16:11
  • I found removing my reference to guava simpler //compile 'com.google.guava:guava:20.0' – Marc Jan 03 '17 at 05:10
  • I got 'duplicate entry: com/google/api/client/util/ArrayMap$Entry.class' – Iman Marashi Jan 21 '17 at 17:51
  • @ImanMarashi, @SuperBale try to run `./gradlew app:dependencies` and check the output – Oleksandr Jan 23 '17 at 12:03
  • I had the same error. I imported a new library that contained an older version of guava but I have imported the newest version of guava before that. At debug compile I got this error: "Duplicate zip entry guava-jdk5-17.0.jar...". I excluded guava from the new imported library compile and it solved the problem. Thanks for the great answer! – Péter Aradi Nov 06 '17 at 19:56
3

I got this error when I had different versions of play services libs in my app module and a library module.

Vasudev
  • 1,936
  • 19
  • 17
2

I found the reason to be the incorrectly configured dagger-compiler:

compile 'com.google.dagger:dagger-compiler:2.1'

What I had done is to modify project' build.gradle:

buildscript {
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
}

And later the application build.gradle:

First, add plugin:

apply plugin: 'com.neenbedankt.android-apt'

And later modify the dependency to:

apt "com.google.dagger:dagger-compiler:2.1"
Paweł Szczur
  • 5,484
  • 3
  • 29
  • 32
  • 1
    I had the same issue, had one entry: apt 'com.google.dagger:dagger-compiler:2.1' and then another: compile 'com.google.dagger:dagger-compiler:2.1' Getting rid of the *compile* entry solved the TransformException for me. – brAzzi64 Jun 04 '16 at 21:10