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

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' testCompile 'junit:junit:4.12' } 

And here is the mistake

 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 delete

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

This is above errors, but other functions do not work as expected. How values ​​/ style can not find

 Theme.AppCompat.Light.DarkActionBar 

How can I duplicate an input error?

+5
source share
3 answers

Delete duplicate libraries.

Although the OP did not record this, if you look at the comments on the original question, you will see that they have several .jar library .jar in the libs directory, which are included in the following line:

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

In one of their comments, they list the following files in the 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 enabled twice, once for version 2.10.1 and once for version 2.10.5 . The build system is not smart enough to cite just one of them, and it shouldn't be. The user must tell the build system which libraries should be included, and which version of each to include.

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

This may not be the problem you are facing, but probably the result of something like that.

To avoid these situations, consider a few best practices:

1. Do not use compile fileTree...

Instead of hiding all the .jar files that you include, explicitly specify which files you are compiling into dependencies {} . This will make viewing easier when you have duplicates, conflicts, and other similar problems.

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

Although he would not catch this using Maven and adding the same dependency with different versions twice, he should allow only one of these dependencies (I think) and avoid a cryptic error, as you can see.

+1
source

Remove duplicated jars and use only the necessary jar and aar files.

+2
source

Try adding this code to your Gradle.

 defaultConfig { multiDexEnabled true } dexOptions { preDexLibraries = false javaMaxHeapSize "4g" } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') } 

or add this class to your application class, if you don't have an Application class, just enter it ...

 public class SomeApplication extends Application { @Override public void onCreate() { super.onCreate(); MultiDex.install(this); } @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } } 
0
source

Source: https://habr.com/ru/post/1242861/


All Articles