[Kotlin][Android]disable runBlocking checker in a UI thread

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.

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"
        }
    }
}

[update]
In 0.27.0, https://github.com/Kotlin/kotlinx.coroutines/blob/master/CHANGES.md#version-0270, the coroutines feature was improved by below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.