【问题标题】:Kotlin native error unresolved reference coroutinesKotlin 原生错误未解决的参考协程
【发布时间】:2020-05-02 14:13:36
【问题描述】:

我正在尝试在 Windows 中构建本机。

我不确定将实现“org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5”的依赖项放在哪里。

我当前的 gradle 文件如下所示:

buildscript {
    ext.kotlin_version = '1.3.72'
    repositories {
        mavenCentral()

    }
    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
    }
}

plugins {
    id 'org.jetbrains.kotlin.multiplatform' version '1.3.72'
}

dependencies {
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5'
}

repositories {
    mavenCentral()
    jcenter()
}
kotlin { 
    mingwX64("mingw") {
        binaries {
            executable {
                // Change to specify fully qualified name of your application's entry point:
                entryPoint = 'sample.main'
                // Specify command-line arguments, if necessary:
                runTask?.args('')
            }
        }
    }
    sourceSets { 
        mingwMain {

        }
        mingwTest {
        }

    }
    experimental {
        coroutines 'enable'
    }

}

此依赖行给出错误:

dependencies {
        implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5'
    }

错误是:

Could not find method implementation() for arguments [org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

如果我删除该依赖项,如果我尝试导入 kotlinx.coroutines.* 和 kotlin.concurrent.thread,我会得到“未解析的引用”

感谢您对此的帮助。

谢谢

【问题讨论】:

    标签: kotlin kotlin-coroutines


    【解决方案1】:

    org.jetbrains.kotlinx:kotlinx-coroutines-core-native

    还有 Kotlin/Native 仅支持 Gradle 4.10 版本,您需要在 settings.gradle 文件中启用 Gradle 元数据:

    enableFeaturePreview('GRADLE_METADATA') 由于 Kotlin/Native 通常不提供版本之间的二进制兼容性,因此您应该使用与构建 kotlinx.coroutines 时使用的相同版本的 Kotlin/Native 编译器。

    https://github.com/Kotlin/kotlinx.coroutines/blob/master/README.md

    【讨论】:

    • @Dimitri 非常感谢。这样就彻底解决了问题。
    • 运行时出现一个问题: fun main() { GlobalScope.launch { delay(1000L) println("World!") } println("Hello,") Thread.sleep(2000L) //没有线程!!包中没有找到线程......未解决的参考......
    • 这里好像也没有 kotlin.concurrent 包!!
    • 是的,并发目前仅适用于 JVM。 kotlinlang.org/api/latest/jvm/stdlib - 向下滚动到并发,你只会看到绿色圆圈(JVM)
    • 是的,现在可以看到。谢谢
    猜你喜欢
    • 2020-07-23
    • 2017-08-08
    • 2021-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-12
    • 2021-12-16
    • 2018-10-25
    相关资源
    最近更新 更多