我将 Kotlin 添加到具有依赖性的 gradle.build(Kotlin 版本 1.0.4):
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
我发现它与我的其他依赖项有冲突:
compile 'org.jetbrains:annotations-java5:15.0'
在我运行构建后它因 ZipException 崩溃:
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/jetbrains/annotations/Nullable.class
我已经尝试过的:
我试过这个解决方案: Kotlin,Java,multidex,Dagger 2,Butterknife and Realm: transformClassesWithJarMergingForDebug: duplicate entry: org/jetbrains/annotations/NotNull.class 但结果是,不仅 Nullable.class 和 NotNull.class 是重复的,而且 org/intellij/lang/annotations/ 中的类也是重复的>。
在我添加了五个类之后它仍然崩溃了。有没有更好的方法来解决这个问题,即不手动添加导致此异常的每个类?
更新 (02.02.16)
当我对这个问题进行一些研究时,我发现对于我的项目,相关的注释类是 NonNls.class
和 Contract.class
,如果我删除了 org.jetbrains:annotations-java5:15.0
。它们不在 kotlin-runtime 中,而是在 Jetbrains 注释依赖项中。如何在不再次添加 Jetbrains 注释依赖项的情况下添加它?
最佳答案
尝试使用而不是:
compile 'org.jetbrains:annotations-java5:15.0'
这个:
compile 'com.android.support:support-annotations:+'
Android 支持库默认像 Kotlin 一样提供了一些最常用的注解,所以如果你使用像 @NonNull
、@Nullable
和 @Null
注释你,去掉上面的依赖。
关于android - Kotlin gradle.build ZipException 因为重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40806977/