Santa
Santa

Reputation: 485

Java and Kotlin combined build error (Duplicate Zip Entry)

I have added Kotlin library to my existing project. After that I'm getting the build error. I commented all the recently added libraries and checked the main problem is after adding kotlin library

Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> java.io.IOException: Can't write [/home/imedrix-server/StudioProjects/kardioscreen-operatorapp/app/build/intermediates/multi-dex/debug/componentClasses.jar] (Can't read [/home/imedrix-server/StudioProjects/kardioscreen-operatorapp/app/build/intermediates/transforms/desugar/debug/76.jar(;;;;;;**.class)] (Duplicate zip entry [76.jar:org/intellij/lang/annotations/Flow.class]))

Project gradle

buildscript {
    ext.kotlin_version = '1.2.21'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:3.0.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath ('com.google.firebase:firebase-plugins:1.0.5') {
            exclude group: 'com.google.guava', module: 'guava-jdk5'
        }
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {url "https://maven.google.com"}
    }
}

And the app gradle

apply plugin: 'com.android.application'

apply plugin: 'com.google.firebase.firebase-crash'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    defaultConfig {
        applicationId 'com.example.android'
        minSdkVersion 20
        targetSdkVersion 27
        versionCode 17
        versionName "1.0"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
//            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        debug {
            buildConfigField("String", "BASE_URL", "\"url\"")
            buildConfigField("String", "API_KEY", "\"key\"")
        }
    }

    productFlavors {
    }
    dexOptions {
        preDexLibraries = false
        javaMaxHeapSize "4g"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude '.readme'
    }
}



dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile project(':controllers')
    compile files('libs/achartengine-1.2.0.jar')
    compile files('libs/dfuLibrary.jar')
    compile 'com.android.support:appcompat-v7:27.0.2'
    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    compile 'com.android.support:design:27.0.2'
    compile 'com.android.support:recyclerview-v7:27.0.2'
    compile 'com.android.support:cardview-v7:27.0.2'
    compile 'com.polidea.rxandroidble:rxandroidble:1.0.2'
    compile 'com.google.firebase:firebase-crash:11.8.0'
    compile 'com.android.support.constraint:constraint-layout:1.1.0-beta4'
    compile 'com.android.support:support-v4:27.0.2'
    compile 'com.google.android.gms:play-services-location:11.8.0'
    compile 'com.jakewharton:butterknife:8.8.1'
    testCompile 'junit:junit:4.12'
    /*compile 'org.hashids:hashids:1.0.3'
        compile 'com.google.dagger:dagger:2.11'
        compile 'javax.inject:javax.inject:1'
        kapt 'com.google.dagger:dagger-compiler:2.11'
        compile 'io.reactivex.rxjava2:rxjava:2.1.3'
        compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
        kapt 'com.jakewharton:butterknife-compiler:8.8.1'
        compile 'com.amitshekhar.android:rx2-android-networking:1.0.0'
        compile 'com.android.support:multidex:1.0.2'*/
}

apply plugin: 'com.google.gms.google-services'

If I remove the below line from the app gradle everything works fine. But if I add the kotlin library I'm getting the error.

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

How can I use the kotlin and Java together.

Upvotes: 5

Views: 874

Answers (1)

Santa
Santa

Reputation: 485

Atlast I found the answer, it was due to duplicate entry to annotation which can be solved by using the below lines in the gradle.

configurations {
        compile.exclude group : 'org.jetbrains' , module : 'annotations'
}

Upvotes: 3

Related Questions