Skip to main content

Android java.util.zip.ZipException: duplicate entry

Android java.util.zip.ZipException: duplicate entry


Recently, I faced this build error while trying to integrate kotlin in our project.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithJarMergingForPreKitkatDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/intellij/lang/annotations/Identifier.class

As you can see, gradle is trying to add same entry two times, referenced by different dependencies.

So to figure out which are those two dependencies, I built the project with some extra options :

./gradlew assembleDebug --stacktrace --info | grep Identifier.class

This was the output:

addJar(/Users/yashasvi/.gradle/caches/modules-2/files-2.1/com.intellij/annotations/12.0/bbcf6448f6d40abe506e2c83b70a3e8bfd2b4539/annotations-12.0.jar): entry org/intellij/lang/annotations/Identifier.class

addJar(/Users/yashasvi/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/919f0dfe192fb4e063e7dacadee7f8bb9a2672a9/annotations-13.0.jar): entry org/intellij/lang/annotations/Identifier.class

As you can see, the culprit here is newly added dependency with group org.jetbrains.

Solution?

It’s simple. Just exclude the appropriate module from one of the dependencies. In my case, the problem was introduced when I was trying to add kotlin-std-lib-jre7 dependency from jetbrains.

So, I changed

compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

to

compile ("org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"){
    exclude module: 'annotations'
}

Let me know in case of any doubts.

Cheers !


Comments

Post a Comment

Popular posts from this blog

Android : AbsSavedState cannot be cast to $SavedState

Android AbsSavedState cannot be cast to $SavedState I came across a strange crash today. This is the stacktrace : Fatal Exception: java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.ScrollView$SavedState at android.widget.ScrollView.onRestoreInstanceState(ScrollView.java:1810) at android.view.View.dispatchRestoreInstanceState(View.java:14768) at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3123) at android.view.View.restoreHierarchyState(View.java:14746) at android.support.v4.app.Fragment.restoreViewState(SourceFile:470) at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1326) at android.support.v4.app.FragmentManagerImpl.moveFragmentsToInvisible(SourceFile:2323) at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(SourceFile:2136) at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(SourceFile:2092) at androi...

Android Tip : Handling back button in Fragments

Android Tip : Handling hardware back button in Fragment and DialogFragment This post explains how to handle hardware back button in a Fragment OR DialogFragment . In DialogFragment, it’s quiet straight forward to achieve this. You’ve to get the dialog instance and set onKeyListener on it : if (getDialog() != null ) { getDialog().setOnKeyListener( new DialogInterface.OnKeyListener() { @Override public boolean onKey (DialogInterface dialog, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) { Timber.i( "hardware back button pressed" ); } } }); } This can be done in the onViewCreated callback. For fragments, this method doesn’t work and fragments doesn’t have a direct callback to catch this event. So in this case, the approach that we follow is : You...

Android Material Showcase View - Part 1

In this series, I'll be talking about a library which is used by a lot of android developers for showcasing their in-app content,  MaterialShowcaseView . I used this library sometime back for my work and had to modify it to fit my needs. In this process, I ended up digging it a lot and would like to share what I learned. The original library offers a fix set of features, which are demonstrated by the screenshots in the README. Let's jump on the technicalities right away. The original library offers two things : 1) highlighting a view ( see the README to know what I mean by highlighting here) 2) showing a content box that tells user what the highlighted view is about. Here's how it does this : The library adds a direct view child ( this class ) in the window decor view, so that it's drawn on top of your activity's view ( here ). Then, for drawing the overlay and highlighting our view, it overrides the `onDraw()` method of this view and uses android...