android - 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")
}
所以我的问题是:
- 为什么SQLDelight会覆盖
kotlinx-coroutines-core
版本? - 为什么Ktor只想要
kotlinx-coroutines-core
带有native-mt
后缀的版本? - 我该如何解决这个版本问题?
解决方案
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 需要版本升级。我可以在接下来的几天里解决这个问题,但不确定什么时候会准备好。你可以等一下吗?