【问题标题】:KMM: sqldelight:coroutines-extensions sets kotlinx-coroutines-core version to 1.3.9KMM: sqldelight:coroutines-extensions 将 kotlinx-coroutines-core 版本设置为 1.3.9
【发布时间】:2021-03-08 04:00:31
【问题描述】:

我在共享模块的 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 一切都会再次正常工作。但我需要该依赖项才能从 db 消耗 Flow

我尝试从 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. 如何解决这个版本问题?

【问题讨论】:

    标签: android ios kotlin-coroutines kotlin-multiplatform sqldelight


    【解决方案1】:

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

    【讨论】:

    • 设置版本严格帮助。但是我必须对coroutines-android 依赖项使用相同的版本才能编译项目。不确定是好是坏。我在尝试解决这个问题时遇到了CoroutinesExtensions 文件。我想如果我不能使扩展工作,我会删除它并复制 KaMPKit 扩展文件。感谢您提供!
    • 如果您能帮助我解决 Ktor 协程混乱,我将不胜感激。在此页面上github.com/Kotlin/kotlinx.coroutines for Multiplatform 它说指定"org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1" 就足够了。但它不适用于 Ktor。我们必须使用 1.4.1-native-mt 吗?或者可能需要更新 Ktor 以支持新版本的协程?
    • 关于最后一个问题,很遗憾,我的信息已过期。我需要刷新当前的情况。当 1.4 发布时,Ktor 转移到了 mt 版本的协程,但仍然有两个不同版本的协程。如果我有机会尽快深入研究它,我会更新它。
    • 好的,所以有一个1.4.1-native-mt 版本的协程。 kotlinlang.org/docs/mobile/…好像是不久前发布的github.com/Kotlin/kotlinx.coroutines/issues/…
    猜你喜欢
    • 2022-08-03
    • 1970-01-01
    • 2021-11-23
    • 2019-10-22
    • 1970-01-01
    • 2016-07-03
    • 1970-01-01
    • 2018-07-15
    • 1970-01-01
    相关资源
    最近更新 更多