关于android:java.lang.ClassNotFoundException:找不到类” kotlinx.coroutines.experimental.Deferred”

java.lang.ClassNotFoundException: Didn't find class “kotlinx.coroutines.experimental.Deferred”

在协同使用协程时遇到了这个问题,请让我知道为什么我会收到此错误

java.lang.ClassNotFoundException:在路径:DexPathList [[zip文件" /data/app/com.coroutines.retrofit.kotlin-1/base.apk"中找不到类" kotlinx.coroutines.experimental.Deferred""],nativeLibraryDirectories = [/ vendor / lib64,/ system / lib64]]

当我使用以下依赖项时,

实现'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-experimental-adapter:1.0.0'

实现'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.1'
实现'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.1'

,kotlin版本为:
ext.kotlin_version ='1.3.10'


Add this dependency in your build.gradle : (remove experimental dependency for coroutine)

1
2
3
4
dependencies {
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0'
    implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'
}

And add CoroutineCallAdapterFactory() for retrofit

1
addCallAdapterFactory(CoroutineCallAdapterFactory())


我面临着同样的问题,这是杰克·沃顿(Jake Warton)的图书馆问题。它在内部使用实验参考。

使用implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-experimental-adapter:1.0.0'

1
2
java.lang.NoClassDefFoundError: Failed resolution of: Lkotlinx/coroutines/experimental/Deferred;
    at com.jakewharton.retrofit2.adapter.kotlin.coroutines.experimental.CoroutineCallAdapterFactory.get

该库已弃用。这是git

上库页面的解决方案

This library is deprecated. Please migrate to Retrofit 2.6.0 or newer and its built-in suspend support