gpt4 book ai didi

kotlin - 在 IntelliJ Kotlinx 错误中运行协程

转载 作者:行者123 更新时间:2023-12-02 13:43:23 25 4
gpt4 key购买 nike

我正在尝试使用 IntelliJ IDEA Community 2020 的协程运行 native Kotlin 项目。
这是我的 build.gradle 的外观:

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

repositories {
mavenCentral()
}

kotlin {
// For ARM, should be changed to iosArm32 or iosArm64
// For Linux, should be changed to e.g. linuxX64
// For MacOS, should be changed to e.g. macosX64
// For Windows, should be changed to e.g. mingwX64
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 {
// Note: To enable common source sets please comment out 'kotlin.import.noCommonSourceSets' property
// in gradle.properties file and re-import your project in IDE.
mingwMain {
}
mingwTest {
}
}

}

// Use the following Gradle tasks to run your application:
// :runReleaseExecutableMingw - without debug symbols
// :runDebugExecutableMingw - with debug symbols
这是一个简单的 KT 文件:
package sample

import kotlinx.coroutines.*

fun main() = runBlocking<Unit> {

val deferred = async(Dispatchers.Unconfined, CoroutineStart.LAZY) {
println("Running Async Unconfined: on thread ${Thread.currentThread().name} has run.")
42
}

val result = deferred.await()
println("Async Unconfined Result is ${result}")

}
我在项目结构下安装了 maven 插件 |附上模块和屏幕截图。
enter image description here
不过,我收到“ Unresolved 引用...”错误。附上截图...
enter image description here
请问有人可以帮我解决这个问题吗?
谢谢

最佳答案

在您的 Project Structure > Modules > Dependencies选项卡,您选择了 Runtime作为范围,这使得依赖项仅在运行时可用(通常用于传递依赖项)。尝试选择Compile这里。

关于kotlin - 在 IntelliJ Kotlinx 错误中运行协程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61380004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com