Reputation: 511
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'
Upvotes: 9
Views: 10455
Reputation: 11
it works: (pay attention to jar task)
plugins {
application
kotlin("jvm") version "1.6.10"
}
group = "org.example"
version = "1.0-SNAPSHOT"
application {
mainClass.set("org.example.MainKt")
}
repositories {
mavenCentral()
}
dependencies {
implementation("io.ktor:ktor-client-core-jvm:1.6.7")
implementation("io.ktor:ktor-client-cio-jvm:1.6.7")
}
tasks {
jar {
manifest {
attributes["Main-Class"] = application.mainClass
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
configurations.compileClasspath.get().forEach {
from(if (it.isDirectory) it else zipTree(it))
}
}
compileKotlin {
kotlinOptions.freeCompilerArgs += "-opt-in=kotlin.ExperimentalStdlibApi"
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}
Upvotes: 1
Reputation: 11110
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
Upvotes: 2
Reputation: 6981
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())
Upvotes: 14