Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio java.util.zip.ZipException: duplicate entry

Tags:

android

here is my build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.arefin.lasttrykinvay"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
repositories {
    flatDir {
       dirs 'libs'
    }
}


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile(name:'kinvey-android-2.10.5', ext:'aar')
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile google-http-client-1.19.0.jar 
    compile google-http-client-android-1.19.0.jar
    compile google-http-client-gson-1.19.0.jar 
    compile google-http-client-jackson2-1.19.0.jar 
    compile gson-2.1.jar guava-18.0.jar 
    compile jackson-core-2.1.3.jar 
    compile java-api-core-2.10.1.jar 
    compile java-api-core-2.10.5.jar 
    compile kinvey-android-2.10.5.aar
    testCompile 'junit:junit:4.12'
}

And here is the error

Error:Execution failed for task ':app:transformClassesWithJarMergingForRelease'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/kinvey/java/AbstractClient$Builder$Option.class

When I remove the

compile 'com.android.support:appcompat-v7:23.1.1'

That above error fixes but other functions dont work properly . Like values/style cant not find

Theme.AppCompat.Light.DarkActionBar

How can I that duplicate entry error ?

like image 249
Yasin Arefin Avatar asked Oct 18 '22 15:10

Yasin Arefin


2 Answers

Remove the duplicate jars and use only required jar and aar files.

like image 53
Raghavendra Avatar answered Oct 21 '22 12:10

Raghavendra


Remove duplicate library dependencies.

Although the OP didn't write this out, if you look at the comments on the original question, you'll see that they have a number of .jar library files in the libs directory, which are all included in the following line:

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

In one of their comments, they list the following files in their libs directory:

  • google-http-client-1.19.0.jar
  • google-http-client-android-1.19.0.jar
  • google-http-client-gson-1.19.0.jar
  • google-http-client-jackson2-1.19.0.jar
  • gson-2.1.jar
  • guava-18.0.jar
  • jackson-core-2.1.3.jar
  • java-api-core-2.10.1.jar Duplicate!
  • java-api-core-2.10.5.jar Duplicate!
  • kinvey-android-2.10.5.aar

You can clearly see that java-api-core is included twice, once for the 2.10.1 version and once for the 2.10.5 version. The build system isn't smart enough to only bring one of these in, and it shouldn't have to be. The user should tell the build system which libraries to be included and which version of each to include.

By removing the java-api-core-2.10.1.jar file from the libs directory, the error should be resolved.

This might not be the exact problem you're running into but it's likely the result of something similar.

To help avoid these situations, here are a couple of best practices:

1. Don't use compile fileTree....

Instead of hiding away all the .jar files that you're including, explicitly state which files you're compiling under dependencies {}. This will make it easier to see when you have duplicates, conflicts and other issues like this.

2. Use Maven instead of .jar files as much as possible.

Although it wouldn't catch this, by using Maven and putting the same dependency twice with different versions it should only resolve one of those dependencies (I think) and avoid a cryptic error like you're seeing.

like image 23
Joshua Pinter Avatar answered Oct 21 '22 12:10

Joshua Pinter