119

I am not sure what this error means.

Execution failed for task ':excelSior:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: android/support/v4/util/TimeUtils.class

I am currently using android-support-v4.jar for my libraries

dependencies {
    compile project(':addThisSDK')
    compile project(':centeredContentButton')
    compile project(':googleplayservices_lib')
    compile files('libs/adxtag2.4.6.jar')
    compile files('libs/android-support-v4.jar')
    compile files('libs/aws-android-sdk-1.7.1.1-debug.jar')
    compile files('libs/commons-lang-2.6.jar')
    compile files('libs/crittercism_v4_4_0_sdkonly.jar')
    compile files('libs/dd-plist.jar')
    compile files('libs/FiksuAndroidSDK_4.1.1.jar')
    compile files('libs/iqengines-sdk-barcode.jar')
    compile files('libs/irEventTracker-1.2.jar')
    compile files('libs/jolt-core-0.0.7.jar')
    compile files('libs/json-utils-0.0.7.jar')
    compile files('libs/jsoup-1.7.2.jar')
    compile files('libs/kooaba-api-v4-java.jar')
    compile 'com.android.support:multidex:1.0.0'
}

Error does not show up during gradle sync. Just when I try to run the application

What could be the problem?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
bman
  • 3,740
  • 9
  • 34
  • 40
  • 1
    The error comes when any other jar dependency of yours have same class, make sure you have not added support jar both as gradle and jar dependency. please include complete dependency closure in the question. – Piyush Agarwal Nov 17 '14 at 07:09
  • @pyus13 thanks. I have updated the question. This is my whole dependency list – bman Nov 17 '14 at 07:16
  • 1
    You have 3 module dependencies in your project, so make sure only one of all them have the support-v4 as dependency. – Piyush Agarwal Nov 17 '14 at 09:21
  • please see my answer at: http://stackoverflow.com/questions/28168063/gradle-duplicate-entry-java-util-zip-zipexception/28937822#28937822 – Tomer Mar 09 '15 at 08:41
  • Error:Execution failed for task ':Mulugu Astro:transformClassesWithJarMergingForDebug'. > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/view/ViewPager$MyAccessibilityDelegate.class – Harsha Feb 10 '17 at 04:55
  • how to solve this error please help me – Harsha Feb 10 '17 at 04:55
  • in my libs am having support-v4.jar – Harsha Feb 10 '17 at 04:56

20 Answers20

81

You've probably fixed this by now but just so this doesn't stay unanswered, Try adding this to your build.gradle:

configurations {
    all*.exclude group: 'com.android.support', module: 'support-v4'
}
Dayan
  • 7,634
  • 11
  • 49
  • 76
zwebie
  • 2,349
  • 1
  • 27
  • 43
  • 4
    I have added the configurations line but still `Error:Execution failed for task ':Analyst:packageAllDebugClassesForMultiDex'. > java.util.zip.ZipException: duplicate entry: com/android/vending/billing/IInAppBillingService$Stub$Proxy.class` it shows. – biswajitGhosh May 19 '15 at 13:44
  • 2
    How did you fix the issue? – Arslan Anwar May 27 '15 at 12:36
  • 9
    is there any right solution.i am getting same problem java.util.zip.ZipException: duplicate entry: com/google/gson/annotations/Expose.class – RamBabu Pudari Jun 02 '15 at 12:52
  • 2
    Error:(5, 30) error: package android.support.v4.app does not exist Getting this error after adding your answer – Ankit Thakkar Oct 09 '15 at 08:14
  • I'm getting this error after adding the configuration in my build.gradle Error:(29, 0) Cannot change configuration ':app:_debugApk' after it has been resolved. – Akeshwar Jha Nov 04 '15 at 05:51
  • 1
    Where is this supposed to go, I'm new to gradle and there are 5 build.gradle files in my current project, none of them have `configurations` in them and it doesn't seem to matter where I put it, I get errors like cannot resolve symbol 'exclude' or cannot resolve symbol 'all' – JStephen Nov 13 '15 at 16:32
  • i am having the same issue **Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/xmlbeans/xml/stream/Location.class** how to fix this i am using android studio @hardartcore – Pankaj Nimgade Nov 19 '15 at 12:11
  • This does not seem to work on AS 1.5 I get the message cannot resolve symbol 'exclude' – Ahmed Faisal Dec 10 '15 at 20:21
  • Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. > com.android.build.transform.api.TransformException: java.util.zip.ZipException: duplicate entry: android/support/multidex/MultiDex$V14.class – Harsha May 10 '16 at 06:06
  • my issue is fixed on higher version but on 2.3 i got same error . – Ram May 16 '16 at 08:07
  • 1
    For Gson Exponse.class error use this `configurations { all*.exclude module: 'gson' }` – Laveen Balakrishna May 25 '16 at 09:40
  • Although this fixed that issue, it meant that any of my code that referenced the `support-v4` library could not resolve. So, use this with care because it's not an ideal solution, it just remove that library entirely from your library dependency compilation. – Joshua Pinter Mar 01 '17 at 15:06
65

You need to check that you have inserted v4 library and compile library? You must not repeat library in your app or your dependence program.

delete the repeat library so that just one V4 remains.

in your app dir build.gradle file add this command:

android{


    configurations {
        all*.exclude group: 'com.android.support', module: 'support-v4'
        all*.exclude group: 'com.android.support', module: 'support-annotations'
    }

}

it works for me! You can try it!

Bernd Wilke πφ
  • 10,390
  • 1
  • 19
  • 38
GeekHades
  • 3,028
  • 3
  • 19
  • 15
25

I also came across this kind issue when re import old eclipse project. It occurred some old dependency as jar file in the project.

just remove

compile fileTree(dir: 'libs', include: '*.jar')

in gradle file

and add dependency in the gradle file.

It works for me ..

  • This error occurred when import old eclipse project sorry,, actually, i removed some of the reference library and add same dependency in gradle file. – Paraneetharan Saravanaperumal Apr 04 '16 at 05:29
  • 1
    Worked for me (also importing from old eclipse configuration). After that clean and rebuild was required. – Paco Abato Jun 24 '16 at 09:42
  • 17
    Why should I trust one named Sauron? – matthias_b_nz Jul 07 '16 at 21:05
  • Stopped this specific error, but caused dozens of others. Sometimes you need those dependencies. As strange as this may sound, Sauron was right this time. – SMBiggs Feb 22 '17 at 04:48
  • you definitely need those dependencies. but my case if i inject those dependencies using lib (manual download), it ll be caused this issue. After that I add those dependencies using 'compile ' . I think most of the time, repeated library caused this issue. so you can exclude those lib. I hope this may helpful. – Paraneetharan Saravanaperumal Feb 22 '17 at 06:47
  • 1
    By adding your dependencies explicitly, one by one, you'll likely uncover a duplicate `.jar` library that you're including twice. Never use `compile fileTree(...)`, it hides too many obvious errors. – Joshua Pinter Mar 01 '17 at 15:07
13

In my case the mentioned "duplicate entry" error arised after settingmultiDexEnable=true in the build.gradle.

In order to fully resolve the error first of all have a look at Configure Apps with Over 64K Methods (espescially "Configuring Your App for Multidex with Gradle").

Furthermore search for occurences of the class that causes the "duplicate entry" error using ctrl+n in Android Studio. Determine the module and dependency that contains the duplicate and exclude it from build, e.g.:

compile ('org.roboguice:roboguice:2.0') {
    exclude module: 'support-v4'
}

I had to try multiple module labels till it worked. Excluding "support-v4" solves issues related to "java.util.zip.ZipException: duplicate entry: android/support/v4/*"

b00n12
  • 1,428
  • 1
  • 12
  • 16
9

My understanding is that there are duplicate references to the same API (Likely different version numbers). It should be reasonably easy to debug when building from the command line.

Try ./gradlew yourBuildVariantName --debug from the command line.

The offending item will be the first failure. An example might look like:

14:32:29.171 [INFO] [org.gradle.api.Task] INPUT: /Users/mydir/Documents/androidApp/BaseApp/build/intermediates/exploded-aar/theOffendingAAR/libs/google-play-services.jar

14:32:29.171 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':BaseApp:packageAllyourBuildVariantNameClassesForMultiDex'

14:32:29.172 [LIFECYCLE] [class org.gradle.TaskExecutionLogger] :BaseApp:packageAllyourBuildVariantNameClassesForMultiDex FAILED'

In the case above, the aar file that I'd included in my libs directory (theOffendingAAR) included the Google Play Services jar (yes the whole thing. yes I know.) file whilst my BaseApp build file utilised location services:

compile 'com.google.android.gms:play-services-location:6.5.87'

You can safely remove the offending item from your build file(s), clean and rebuild (repeat if necessary).

user01000101
  • 421
  • 4
  • 13
9

check your dependencies versions, you must have compatible versions put attention specially to com.google packages, must have same version like:

compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.google.android.gms:play-services-maps:8.3.0'

Both are 8.3.0, if you have another version compilation will throw that exception.

Ninja Coding
  • 1,357
  • 1
  • 16
  • 26
  • Thanks Man, Working perfect, I have three different google play services compile 'com.google.android.gms:play-services-analytics:8.4.0' compile 'com.google.android.gms:play-services-ads:8.3.0' compile 'com.google.android.gms:play-services-plus:8.4.0' – Samadhan Medge Apr 05 '16 at 08:43
5

Simple Remove Your Jar file from dependencies gardle.project as v7 and run your project

  • That's work for me, simply remove "compile files('libs/android-support-v13.jar')" form "dependencies" in my "build.gradle (Module: app)". For reference y get this error after import project form eclipse to Android Studio. – rafaellorey Feb 02 '16 at 01:06
5

For Expose.class Error i.e

java.util.zip.ZipException: duplicate entry: com/google/gson/annotations/Expose.class

use the below code

configurations {
    all*.exclude  module: 'gson'
}
3

find out the lib depends on the support v4, and exclude it.

code in build.gradle is like this:

androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') {
    // http://stackoverflow.com/a/30931887/5210
    exclude group: 'com.android.support', module: 'appcompat'
    exclude group: 'com.android.support', module: 'support-v4'
    exclude module: 'recyclerview-v7'
}

In my situation, the lib 'espresso' has a jar called support-v4 and in my project 'app' have the same support-v4, exclude the support-v4 when import espresso.

PS: it seems compile project can not work with the exclude

Ninja
  • 2,479
  • 3
  • 23
  • 32
1

This is because you have added a library and given its dependency on a module more than once.

In my case, I had added a library as a module and as a gradle dependency both.

Removing one source of adding library (I removed gradle dependency) solved my problem.

Rahul Rastogi
  • 4,486
  • 5
  • 32
  • 51
0

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

Here is what I did:

1) Delete the gson-2.5.jar file. 2) configurations { all*.exclude module: 'gson-2.5' }

LEMUEL ADANE
  • 8,336
  • 16
  • 58
  • 72
0

I have faced this issue as i have manually copied the jar in libs as well as mentioned the dependency in gradle file. You also check in your project structure, whether the same jar file is copied in any other folder like libs or in project folder.

Ashish Rawat
  • 5,541
  • 1
  • 20
  • 17
0

I had the same problem after upgrading the android SDK. I was able to run the application in the buildToolsVersion '23.0.1', I got the same error when I changed to buildToolsVersion '24.0.3'

I resolved the problem by updating my java version from 1.7 to 1.8 with compileSdkVersion 24

Muhamed Riyas M
  • 5,055
  • 3
  • 30
  • 31
0

This problem cost me one whole day. I finally downgraded the firebase-ui library version from 2.0.0 to 1.2.0 and added the following code inside Project level build.gradle file:

allprojects {
    repositories {
        jcenter()

        // Add the following code to your project level build.gradle
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
}
Darush
  • 11,403
  • 9
  • 62
  • 60
0

I also have the issue because of i have compile 'com.android.support:appcompat-v7:24.0.0-alpha1' but i added recyclerview liberary compile 'com.android.support:recyclerview-v7:24.0.2'..i changed the version as same as compat like (24.0.2 intead of 24.0.0).

i got the answer..may be it will help for someone.

S HemaNandhini
  • 333
  • 3
  • 5
0

In my case the mentioned "duplicate entry" error arised after settingmultiDexEnable=true in the build.gradle.

and exact error which i was getting was below :

Error:Execution failed for task 
':android:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: 
java.util.zip.ZipException: duplicate entry: 
com/google/android/gms/internal/zzqx.class

So first thing I search for class which causes "duplicate entry" error using ctrl+n in Android Studio and searched for com/google/android/gms/internal/zzqx.class and then it was showing 2 entries for gms class with one version 8.4.0 and 1 with version 11.6.0 .

To fix it i made both to use 11.6.0 and it was fixed example

earlier

    compile "com.google.android.gms:play-services-games:11.6.0"
    compile "com.google.android.gms:play-services-auth:8.4.0"
    compile "com.google.android.gms:play-services-ads:11.6.0"

After

    compile "com.google.android.gms:play-services-games:11.6.0"
    compile "com.google.android.gms:play-services-auth:11.6.0"
    compile "com.google.android.gms:play-services-ads:11.6.0"

Rebuilding Fixed .

paarth batra
  • 1,392
  • 4
  • 29
  • 53
0

In my case exact error was below

':android:transformClassesWithJarMergingForDebug'.

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzqx.class

I was using another version of google apis i.e. in one modules gradle file

if (!project.hasProperty('gms_library_version')) {
        ext.gms_library_version = '8.6.0'
   }

however in other modules version 11.6.0 as below

   compile "com.google.android.gms:play-services-ads:11.6.0"
    compile "com.google.android.gms:play-services-games:11.6.0"
    compile "com.google.android.gms:play-services-auth:11.6.0"

However to find this i did a ctrl + n in android studio and entered class name zzqx.class and then it displayed 2 jar files being pulled for this class and then i understood that somewhere i am using version 8.6.0 . On changing 8.6.0 to 11.6.0 and rebuilding the project the issue was fixed .

Hope this helps .

More on this here https://www.versionpb.com/tutorials/step-step-tutorials-libgdx-basic-setup-libgdx/implementing-google-play-services-leaderboards-in-libgdx/

paarth batra
  • 1,392
  • 4
  • 29
  • 53
0

For me something similar happened when I had accidently added

apply plugin: 'kotlin-android'

to my android library module. Removing the line fixes the issue.

A. Steenbergen
  • 3,360
  • 4
  • 34
  • 51
0

I tried all the above solutions but not working for me. I tried update libraries by goto project structure > app. And it works for me! Hope this answer helpful to someone.

Pooja
  • 475
  • 5
  • 14
-1

Try this:

android {
configurations {
        all*.exclude  module: 'PhotoView'  //去除重复依赖库
    }
}
xlm
  • 6,854
  • 14
  • 53
  • 55
badboy_tqj
  • 300
  • 2
  • 14