kotlinx.coroutines: AbstractMethodError when use withTimeout
I am getting the following error java.lang.AbstractMethodError: abstract method "kotlinx.coroutines.DisposableHandle kotlinx.coroutines.Delay.invokeOnTimeout(long, java.lang.Runnable, kotlin.coroutines.CoroutineContext)" when calling the withTimeout method into commonMain module.
override suspend fun notifyCharacteristic(uuid: String, enabled: Boolean): Flow<ByteArray> {
return withTimeout(2000) {
bluetoothDataSource.watchConnectionState().filter {
it == DeviceConnectionState.STATE_DISCOVERED
}.first()
val charac = retrieveCharacteristic(characteristics, uuid)
?: throw IllegalStateException("Characteristic is null")
bluetoothDataSource.notifyCharacteristic(
charac,
enabled,
"00002902-0000-1000-8000-00805f9b34fb"
).map { it.toByteArray() }
}
}
My project is configured in this way:
getByName("commonMain") {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.0-M1")
}
}
getByName("androidMain") {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.0-M1")
}
}
getByName("iosMain") {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.0-M1")
}
}
Can be the notifyCharacteristic function bad written?
Thank you
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 15 (4 by maintainers)
@mkotyk
What platform? And which dependency are you using?
If on Android, I had the same issue and fixed it as follows:
Originally I used
org.jetbrains.kotlinx:kotlinx-coroutines-core:, but reading comments here, I switched toorg.jetbrains.kotlinx:kotlinx-coroutines-android:. That helped.I’m seeing this too, and it’s related to using
debouncewith 1.4.0 … once I took the debounce out, the crash stopped.Here’s my usage:
I’ve came across this issue when I was working on Mockk tests in my project. In my case, it was caused by different versions of
org.jetbrains.kotlinx:kotlinx-coroutines-androidandorg.jetbrains.kotlinx:kotlinx-coroutines-test. Updating both of them to1.4.1fixed the issue, maybe it will help somenone.Likely a version mismatch like in #1033
kotlinx-coroutines-coreis a multiplatform library (JVM, common, Native, JS), but with recent additions to multiplatform plugin you may forget about various variants and use it as is in common source set.kotlinx-coroutines-androidis not a multiplatform variant. It’s a standalone JVM library that contains various utilities for Android development, e.g.Dispatchers.Mainimplementation. Typically, you should include it if you are working with Android. And thenstrictversion should be used to avoid version mismatch ofkotlinx-coroutines-coreandkotlinx-coroutines-android