将项目更新为稳定的协程 Kotlin 1.3.0 + Coroutines 1.0.0 错误
Updating project to stable coroutines Kotlin 1.3.0 + Coroutines 1.0.0 error
我在我的项目中指定了以下内容:
模块
dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version'
}
项目
buildscript {
ext.kotlin_version = '1.3.0'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
包装器
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
Gradle 同步完成且没有错误,但是我对
的每次调用
GlobalScope.launch {}
'launch' 标记为以下错误:
'Unsupported [cannot use release coroutines with api version less than 1.3]'
我已经失效并干净地重建了 - 我错过了什么?
**编辑
我可以看到错误产生的地方:
kotlin/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/coroutineCallChecker.kt
fun checkCoroutinesFeature(languageVersionSettings: LanguageVersionSettings, diagnosticHolder: DiagnosticSink, reportOn: PsiElement) {
if (languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines)) {
if (languageVersionSettings.apiVersion < ApiVersion.KOTLIN_1_3) {
diagnosticHolder.report(Errors.UNSUPPORTED.on(reportOn, "cannot use release coroutines with api version less than 1.3"))
}
return
}
您的依赖项中缺少标准库。该插件会检查它以确定要使用的 api 版本。
添加 "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
作为依赖项以修复您的错误。
右键单击项目名称 -> Maven -> 重新导入。
就我而言,它有所帮助。
清除您的 m2 缓存并重新导入所有依赖项。那应该可以解决问题。原因是,如果它之前工作,那么您拥有所需的所有依赖项,并且通过清除缓存,您可以重新获取 运行 协程所需的所有必需库。
如果你之前没问题,这可能是你新添加的依赖项之一。我就是这种情况,我添加了 "squash" 的过时版本并得到了完全相同的错误。将 "squash" 更新到最新版本后一切正常。
IntelliJ 2019.2.1 对我有用的地方 + Gradle
File => Project Structure
然后从项目设置对话框 select Modules
并为每个 Kotlin 模块确保 语言版本 和 API 版本 匹配。不幸的是,这些设置在每次 Gradle 同步后都会重置,因此您必须在每次 Gradle 同步后重复该过程。
**.
我在我的项目中指定了以下内容:
模块
dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version'
}
项目
buildscript {
ext.kotlin_version = '1.3.0'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
包装器
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
Gradle 同步完成且没有错误,但是我对
的每次调用GlobalScope.launch {}
'launch' 标记为以下错误:
'Unsupported [cannot use release coroutines with api version less than 1.3]'
我已经失效并干净地重建了 - 我错过了什么?
**编辑
我可以看到错误产生的地方:
kotlin/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/coroutineCallChecker.kt
fun checkCoroutinesFeature(languageVersionSettings: LanguageVersionSettings, diagnosticHolder: DiagnosticSink, reportOn: PsiElement) {
if (languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines)) {
if (languageVersionSettings.apiVersion < ApiVersion.KOTLIN_1_3) {
diagnosticHolder.report(Errors.UNSUPPORTED.on(reportOn, "cannot use release coroutines with api version less than 1.3"))
}
return
}
您的依赖项中缺少标准库。该插件会检查它以确定要使用的 api 版本。
添加 "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
作为依赖项以修复您的错误。
右键单击项目名称 -> Maven -> 重新导入。 就我而言,它有所帮助。
清除您的 m2 缓存并重新导入所有依赖项。那应该可以解决问题。原因是,如果它之前工作,那么您拥有所需的所有依赖项,并且通过清除缓存,您可以重新获取 运行 协程所需的所有必需库。
如果你之前没问题,这可能是你新添加的依赖项之一。我就是这种情况,我添加了 "squash" 的过时版本并得到了完全相同的错误。将 "squash" 更新到最新版本后一切正常。
IntelliJ 2019.2.1 对我有用的地方 + Gradle
File => Project Structure
然后从项目设置对话框 select Modules
并为每个 Kotlin 模块确保 语言版本 和 API 版本 匹配。不幸的是,这些设置在每次 Gradle 同步后都会重置,因此您必须在每次 Gradle 同步后重复该过程。