Weird Coroutines Reference Issue

Recently, I encountered a weird issue with coroutines in Kotlin. A library that references a coroutine version that differed from my Kotlin’s coroutine could not compile. It resulted in the following error being displayed.

Cannot access 'kotlinx.coroutines.CoroutineScope' which is a supertype of '.....'.

This is probably related to an Application Binary Interface (ABI) issue where a low-level C compiled code has some non-breaking changes but as the ABI has changed, a recompilation is required. In this case, I could either recompile Kotlin coroutines + referenced library, or I could just state the same exact coroutine version used by the referenced library.

In my Gradle build (build.gradle) file, I added this new line:

compile group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: coroutinesVersion

And in my Gradle properties (gradle.properties) file, I specified my the variable:

coroutinesVersion=1.3.2

If you’re using Maven, then you can change your configuration like this:

<properties>
     <coroutines.version>1.3.2</kotlin.version>
</properties>
...
<dependency>
    <groupId>org.jetbrains.kotlinx</groupId>
    <artifactId>kotlinx-coroutines-core</artifactId>
    <version>${coroutines.version}</version>
</dependency>

The fix is absurdly easy despite of the weird and cryptic error message. I hope this was helpful to you and helped you understood what might have happened to cause this issue to occur.

Author: Woo Huiren

Currently a student at National University of Singapore. I contribute to opensource projects - primarily PHP and Angular related. I write about PCF and PWS related stuff too.

Leave a Reply