This post is completely my personal memo.
Recent kotlinx.coroutines has raising exception when runBlocking runs on a UI thread by default. The runBlocking is used to block current thread interruptibly until its completion.
- https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.experimental/run-blocking.html
- https://github.com/Kotlin/kotlinx.coroutines/blob/7764e43c6fe9640615747f7830e8aae1b9bc26d2/docs/basics.md#bridging-blocking-and-non-blocking-worlds
In 0.25.0, the runBlocking has https://github.com/Kotlin/kotlinx.coroutines/issues/464 .
As a workaround, we can disable the checker as below.
android {
...
testOptions {
unitTests.all {
systemProperty "kotlinx.coroutines.blocking.checker", "disable"
}
}
}
- https://github.com/Kotlin/kotlinx.coroutines/pull/458#issuecomment-408737581
- https://github.com/Kotlin/kotlinx.coroutines/issues/227
[update]
In 0.27.0, https://github.com/Kotlin/kotlinx.coroutines/blob/master/CHANGES.md#version-0270, the coroutines feature was improved by below.