4

I add Kotlin to the gradle.build with dependency (Kotlin version 1.0.4):

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

As I found out it has a conflict with my other dependency:

compile 'org.jetbrains:annotations-java5:15.0'

After I run the build it crashes with the ZipException:

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/jetbrains/annotations/Nullable.class

What I already tried:

I tried this solution: Kotlin,Java,multidex,Dagger 2,Butterknife and Realm: transformClassesWithJarMergingForDebug: duplicate entry: org/jetbrains/annotations/NotNull.class But it ended up, that not only Nullable.class and NotNull.class were duplicates, but also classes from org/intellij/lang/annotations/.

After I added five classes it still crashed. Is there a better way to get rid of this problem, by not adding every class manually that causes this exception?

UPDATE (02.02.16)

As I worked a bit on the problem, I found out that for my project the relevant annotation classes are NonNls.class and Contract.class that are missing, if I remove org.jetbrains:annotations-java5:15.0. They are not in kotlin-runtime, but in the Jetbrains annotation dependency. How can I add it without adding the Jetbrains annotation dependency again?

Community
  • 1
  • 1
alexfi
  • 370
  • 2
  • 11
  • `kotlin-runtime` only bundles 4 annotations: `Nullable`, `NotNull`, `Mutable` and `ReadOnly`. So if you have other annotations clashing, they might come from another dependency. – Ilya Nov 28 '16 at 00:21
  • Thank for your answer @Ilya. The solution I tried, worked with `NotNull` and `Nullable`. After that `Flow.class` was a duplicate. As I added `Flow.class` to the list for overriding the annotations.jar, another class was the problem. I think the problem is still with `annotations-java5`. – alexfi Nov 28 '16 at 19:15
  • The simple way would be remove `compile 'org.jetbrains:annotations-java5:15.0'` as android-support library provides its own annotations, so try to use them intead of that got from IntelliJ. – piotrek1543 Dec 02 '16 at 07:33
  • how did you solve please tell. i am also stuck with this problem – Aditay Kaushal Jul 19 '17 at 13:56

1 Answers1

1

Try to use instead of:

compile 'org.jetbrains:annotations-java5:15.0'

this:

compile 'com.android.support:support-annotations:+'

Android support libraries by default provides like Kotlin a few most used annotations, so if you use basiscs like @NonNull, @Nullable and @Null annotations you, remove above dependency.

piotrek1543
  • 19,130
  • 7
  • 81
  • 94
  • Thank you for your answer! :) Necessary for me is the NonNls annotation. As I see, it is not included in `'com.android.support:support-annotations:+'`. The project is too big to refactor all the NonNls annotation usages. – alexfi Dec 02 '16 at 09:22
  • remove both dependencies and change import to 'javax.annotation.NonNull' – piotrek1543 Dec 02 '16 at 11:13