如果我尝试在Gradle项目中升级到最新的Kotlin版本,构建我的Android子项目时会出现以下错误:
e: /(redacted)/AndroidLauncher.kt: (8, 15): Cannot access built-in declaration 'kotlin.Unit'. Ensure that you have a dependency on the Kotlin standard library
回退到1.3.31版本没有问题。我也尝试将com.android.tools.build版本从3.4.0升级到3.4.1,但是没有任何改变。
错误提示表明有问题找不到Kotlin STL。是否需要添加新依赖项或应用插件?
build.gradle
文件中的classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
条目和应用程序模块的dependencies
闭包中的implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
条目。org.jetbrains.kotlin
组件组中的其他内容也应该使用相同的版本。 - CommonsWaregradle.properties
中定义了kotlinVersion
,然后在其他地方重复使用它。 - EntangledLoopsimplementation(kotlin("stdlib"))
依赖项。 - Alexey Belkov