1.0.0
ktor-client-cio
Android 4.2, kotlin_version = '1.3.10', kotlinx-coroutines-core:1.0.1, kotlinx-coroutines-android:1.0.1
The client crashes when trying to execute request. Stack trace:
11-27 20:57:31.300 28676-28713/com.example.android.kotlincoroutines E/dalvikvm: Could not find class 'io.ktor.client.engine.cio.CIOEngine$executeRequest$$inlined$with$lambda$1', referenced from method io.ktor.client.engine.cio.CIOEngine.executeRequest
11-27 20:57:31.394 28676-28716/com.example.android.kotlincoroutines E/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-1
java.lang.ClassCastException: java.nio.SelectorImpl cannot be cast to java.io.Closeable
at io.ktor.network.selector.ActorSelectorManager$1.invokeSuspend(ActorSelectorManager.kt:38)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:236)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594)
at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:742)
11-27 20:57:31.469 478-499/? E/AppErrorDialog: Failed to get ILowStorageHandle instance
On Android 8.0 its functioning properly. Also ktor-client-android doesn't crash on Android 4.2
The code to reproduce crash:
private val uiScope = CoroutineScope(Dispatchers.Main + viewModelJob)
....
fun doSomeNetworkCall() {
uiScope.launch {
Log.d("MainViewModel", "Loading started")
val ioJob = async (Dispatchers.IO) {
testSusp()
}
val result = ioJob.await()
Log.d("MainViewModel", "Loading finished. Result: $result")
}
}
suspend fun testSusp() : String {
val client = HttpClient(CIO)
return client.get("https://httpstat.us/200")
}
....
Hi, @gabin8. Thanks for the report
It's a known problem. Unfortunately, the CIO engine supports only API level 24 or higher(Android >= 8.0)
Consider Android or OkHttp engine instead.
related #732