ZipException: duplicate entry in Kotlin classes

Please note that this project was successfully compiled before upgrading to Android Studio 3.1, Gradle build tools 3.1.0 and Gradle Wrapper 4.4.

An exception occurs during the Gradle transformClassesAndResourcesWithPrepareIntermediateJarsForSomethingDebug task:

Caused by: java.util.zip.ZipException: duplicate entry: com/me/utils/model/singleModel/NodeModel.class

Note that the exception only occurs on Kotlin classes (e.g. NodeModel above). If I remove this class, an exception will occur in the next Kotlin class.

All other SO issues that mention this exception were somehow related to duplicating third-party libraries from project dependencies. This, however, is not my business, as NodeModel is its own class, which I wrote myself. This is just a simple Kotlin data class.

The project uses Kotlin version 1.2.30, build tools 27.0.3, support library 27.1.0 and Firebase 12.0.1.

I tried to clean and rebuild the project several times, changing my local JDK and built-in, nothing works.

I tried running Gradle with --stacktrace --debug to find out where the duplicate was coming from, but Gradle logs didn't mention anything meaningful.

+9
source share
3 answers

Updated Answer

Even with the workaround mentioned below, I still got a random exception. Now that Android Studio 3.1.1 is released, the problem has completely disappeared. Just make sure you also upgrade version 3.1.1 of the Gradle build tools and at least version 4.4 of the Gradle shell:

In gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

In the project build.gradle:

buildscript {
    ...
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.1'
        ...
    }
}

Gradle Wrapper 4.6 , . .

, , Gradle Wrapper 4.3.1 Gradle 3.0.0 , Gradle .

gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.3.1-all.zip

build.gradle:

buildscript {
    ...
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        ...
    }
}
+4

, , ( ). Android Gradle Plugin 3.2.0-beta02 3.1.3 .

0

Solve the problem of splitting java and kotlin sources into separate modules. Do not mix Java and Kotlin in one module. This creates some weird duplication errors, even I only have one class

0
source

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


All Articles