Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am facing this issue when using coroutine with retrofit, can you please let me know why i am getting this error

java.lang.ClassNotFoundException: Didn't find class "kotlinx.coroutines.experimental.Deferred" on path: DexPathList[[zip file "/data/app/com.coroutines.retrofit.kotlin-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]

while i am using the below dependencies,

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

implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.1' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.1'

and the kotlin version is : ext.kotlin_version = '1.3.10'

like image 687
Hemendra Gangwar Avatar asked Dec 10 '18 06:12

Hemendra Gangwar


2 Answers

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

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

addCallAdapterFactory(CoroutineCallAdapterFactory())
like image 118
Shweta Chauhan Avatar answered Dec 14 '22 22:12

Shweta Chauhan


I am facing the same problem, it is the Jake Warton's library problem. It is using experimental references internally.

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

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

This library is deprecated . Here is the solution from the library's page on git

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

like image 40
Rainmaker Avatar answered Dec 14 '22 22:12

Rainmaker