Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Program type already present: kotlinx.coroutines.experimental.EventLoopBase

I am getting the following errors in my kotlin android app

Android issues: (3 errors)

Program type already present: kotlinx.coroutines.experimental.EventLoopBase Message{kind=ERROR, text=Program type already present: kotlinx.coroutines.experimental.EventLoopBase, sources=[Unknown source file], tool name=Optional.of(D8)}

Program type already present: kotlinx.coroutines.experimental.internal.LockFreeLinkedListNode Message{kind=ERROR, text=Program type already present: kotlinx.coroutines.experimental.internal.LockFreeLinkedListNode, sources=[Unknown source file], tool name=Optional.of(D8)}

Program type already present: kotlinx.coroutines.experimental.internal.LockFreeMPSCQueueCore Message{kind=ERROR, text=Program type already present: kotlinx.coroutines.experimental.internal.LockFreeMPSCQueueCore, sources=[Unknown source file], tool name=Optional.of(D8)}

Java compiler: (4 errors)

Caused by: com.android.builder.dexing.DexArchiveBuilderException: Failed to process /home/deepak/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-core/0.25.0/5664ba2d20c6dcc88c912cc9666baa7f03203bcd/kotlinx-coroutines-core-0.25.0.jar

Caused by: com.android.builder.dexing.DexArchiveBuilderException: Error while dexing.

Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete

Caused by: com.android.tools.r8.utils.AbortException

Below is my dependencies and kotlin experimental coroutine

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-rc01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'

implementation 'org.jetbrains.anko:anko:0.10.5'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.25.0'
implementation 'com.android.support:design:28.0.0-rc01'
}

kotlin {
    experimental {
        coroutines "enable"
    }
}
like image 411
Deepak Kumar Avatar asked Aug 30 '18 12:08

Deepak Kumar


2 Answers

It is a bug introduced in kotlinx.coroutines 0.25.0.

Version 0.25.0 was shipped in the form of multi-release JAR and such JAR breaks literally all Android tooling except newest alpha versions. This change was reverted in version 0.25.3, so updating kotlinx.coroutines version and invalidating caches is enough to fix the issue.

like image 55
qwwdfsad Avatar answered Dec 01 '22 23:12

qwwdfsad


Finally, after lot of combinations and research I found a solution for this but certainly it's not a permanent solution.

I found out that using the two dependency Kotlin Coroutine and androidx dependencies at the same time causing the problem So, I removed both of them, and now I am using the android dependencies instead of androidx. Now, my dependencies look like this:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    implementation 'org.jetbrains.anko:anko:0.10.5'
    implementation 'org.jetbrains.anko:anko-design:0.10.5'
    implementation 'com.android.support:design:28.0.0-rc01'
}
kotlin {
    experimental {
        coroutines "enable"
    }
}

Thanks to @Sayem for the help

happyCoding!

like image 25
Deepak Kumar Avatar answered Dec 02 '22 00:12

Deepak Kumar