首页 > 解决方案 > KMM: sqldelight:coroutines-extensions 将 kotlinx-coroutines-core 版本设置为 1.3.9

问题描述

我在 share 模块的build.gradle.kts文件中有这些依赖项。

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

当我运行该应用程序时,一切都在 android 应用程序中运行良好。但是运行 ios 应用程序时出现运行时崩溃。在日志中,我看到这Ktor是在抱怨协程版本不是native-mt. 我不明白为什么,因为 1.4.# 版本的协程没有单独的本机多线程分支。

我查看了 External Libraries 文件夹,发现我的协程版本一直设置为 1.3.9。如果我删除com.squareup.sqldelight:coroutines-extensions一切都会再次正常工作。但是我需要Flow从 db 中使用该依赖项。

我尝试从 sqldelight 扩展中排除协程,但它没有在 Xcode 构建中编译。

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

所以我的问题是:

  1. 为什么SQLDelight会覆盖kotlinx-coroutines-core版本?
  2. 为什么Ktor只想要kotlinx-coroutines-core带有native-mt后缀的版本?
  3. 我该如何解决这个版本问题?

图片

标签: androidioskotlin-coroutineskotlin-multiplatformsqldelight

解决方案


1 - 这是 SQLdelight 使用的版本。Gradle 决定加入那个与 ktor 想要的东西。

2 - Ktor 现在需要多线程版本。

3 - 解决方案

a - 强制 ktor 想要的版本。用版本定义协程依赖,并严格:

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

b - Coroutines 扩展是一个文件。我们需要更新 KaMPKit 并删除它,但我们将一个版本复制到源中以避免 SQLDelight 的早期问题:https ://github.com/touchlab/KaMPKit/blob/master/shared/src/commonMain/kotlin/co /touchlab/kampkit/sqldelight/CoroutinesExtensions.kt

c - SQLDelight 需要版本升级。我可以在接下来的几天里解决这个问题,但不确定什么时候会准备好。你可以等一下吗?


推荐阅读