KMM: sqldelight:coroutines-extensions sets kotlinx-coroutines-core version to 1.3.9

871 views Asked by At

I have these dependencies in my build.gradle.kts file in share module.

val coroutinesVersion = "1.3.9-native-mt"
val serializationVersion = "1.0.1"
val ktorVersion = "1.4.2"
val sqlDelightVersion = "1.4.4"

sourceSets {
    val commonMain by getting {
        dependencies {
            implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
            implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion")
            implementation("io.ktor:ktor-client-core:$ktorVersion")
            implementation("io.ktor:ktor-client-serialization:$ktorVersion")
            implementation("com.squareup.sqldelight:runtime:$sqlDelightVersion")
            implementation("com.squareup.sqldelight:coroutines-extensions:$sqlDelightVersion")
        }
    }
    ...
}

When I run the app everything works fine in android app. But I get a runtime crash when running the ios app. In logs, I see that Ktor is complaining about coroutines version not being native-mt. Which I don't understand why because 1.4.# version of coroutines don't have separate native multithreaded branches.

I looked at the External Libraries folder and found that coroutines version in my case was set to 1.3.9 all the time. If I remove com.squareup.sqldelight:coroutines-extensions Everything works just fine again. But I need that dependency to consume Flow from db.

I tried excluding coroutines from sqldelight extension but it didn't compile in Xcode build.

implementation("com.squareup.sqldelight:coroutines-extensions:$sqlDelightVersion") {
    exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core")
}

So my questions are:

  1. Why does SQLDelight override kotlinx-coroutines-core version?
  2. Why does Ktor want kotlinx-coroutines-core versions only with native-mt suffix?
  3. How can I solve this versions problem?

image

1

There are 1 answers

4
Kevin Galligan On BEST ANSWER

1 - That's the version SQLdelight uses. Gradle made a decision to pull in that one vs what ktor wants.

2 - Ktor now needs the multithreaded version.

3 - Solutions

a - Force the version ktor wants. Define the coroutines dependency with version and strictly:

implementation(Deps.Coroutines.common) {
            version {
                strictly(Versions.coroutines)
            }
        }

b - The Coroutines extension is one file. We need to update KaMPKit and remove this, but we had a version copied into the source to avoid earlier issues with SQLDelight: https://github.com/touchlab/KaMPKit/blob/master/shared/src/commonMain/kotlin/co/touchlab/kampkit/sqldelight/CoroutinesExtensions.kt

c - SQLDelight needs a version bump. I can hack away at that over the next few days, but not sure when that will be ready. You can just wait for that?