程序类型已存在:kotlinx.coroutines.experimental.EventLoopBase

问题描述 投票:7回答:3

我在我的kotlin安卓应用程序中收到以下错误

Android问题:(3个错误) 程序类型已存在:kotlinx.coroutines.experimental.EventLoopBase消息{kind = ERROR,text =程序类型已存在:kotlinx.coroutines.experimental.EventLoopBase,sources = [未知源文件],工具名称= Optional.of(D8) } 程序类型已存在:kotlinx.coroutines.experimental.internal.LockFreeLinkedListNode消息{kind = ERROR,text =程序类型已存在:kotlinx.coroutines.experimental.internal.LockFreeLinkedListNode,sources = [未知源文件],工具名称=可选。的(D8)} 程序类型已存在:kotlinx.coroutines.experimental.internal.LockFreeMPSCQueueCore消息{kind = ERROR,text =程序类型已存在:kotlinx.coroutines.experimental.internal.LockFreeMPSCQueueCore,sources = [未知源文件],工具名称=可选。的(D8)} Java编译器:(4个错误) 引起:com.android.builder.dexing.DexArchiveBuilderException:无法处理/home/deepak/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-core/0.25.0/ 5664ba2d20c6dcc88c912cc9666baa7f03203bcd / kotlinx协同程序核心-0.25.0.jar 引起:com.android.builder.dexing.DexArchiveBuilderException:dexing时出错。 引起:com.android.tools.r8.CompilationFailedException:编译未能完成 引起:com.android.tools.r8.utils.AbortException

下面是我的依赖和kotlin实验协同程序

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"
    }
}
android kotlin build.gradle kotlinx.coroutines
3个回答
5
投票

它是在bug 0.25.0中引入的kotlinx.coroutines

版本0.25.0以multi-release JAR的形式发布,这样的JAR打破了除最新的alpha版本之外的所有Android工具。此更改已在版本0.25.3中还原,因此更新kotlinx.coroutines版本和使缓存无效就足以解决问题。


1
投票

最后,经过大量的组合和研究,我找到了解决方案,但肯定不是永久的解决方案。

我发现使用两个依赖Kotlin Coroutine和androidx依赖同时导致问题所以,我删除了它们,现在我使用android依赖而不是androidx。现在,我的依赖项看起来像这样:

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"
    }
}

感谢@Sayem的帮助

happyCoding!


0
投票

您可以使用版本0.21而不是0.25.0

    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.21'
© www.soinside.com 2019 - 2024. All rights reserved.