在Android Studio中运行Kotlin模块时执行失败

bgibtngc  于 2023-06-04  发布在  Android
关注(0)|答案(1)|浏览(217)

我在运行Kotlin模块时在Build Output中得到以下错误:-

Execution failed for task ':Test:compileKotlin'.
> 'compileJava' task (current target is 1.7) and 'compileKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version.
Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --scan to get full insights.

此模块的build.gradle文件包含以下代码:

plugins {
    id 'java-library'
    id 'org.jetbrains.kotlin.jvm'
}

java {
    sourceCompatibility = JavaVersion.VERSION_1_7
    targetCompatibility = JavaVersion.VERSION_1_7
}

请帮助我找到错误及其解决方案。

jdgnovmf

jdgnovmf1#

试着让Java版本17不像1.7这样:

plugins {
id 'java-library'
id 'org.jetbrains.kotlin.jvm'
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

相关问题