jvm 'compileLoggJavaWithJavac'任务(当前目标是1.8)和'compileLoggKotlin'任务(当前目标是17)

bkkx9g8r  于 12个月前  发布在  Java
关注(0)|答案(1)|浏览(365)

我正在Android Studio中构建一个flutter应用程序,在尝试构建应用程序时安装程序包后一直出现此错误。这是完整的错误消息:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':flutter_image_compress_common:compileDebugKotlin'.
> 'compileDebugJavaWithJavac' task (current target is 1.8) and 'compileDebugKotlin' 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 --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

字符串
由于错误指出当前的目标是版本1.8,我尝试调整android/app/build.gradle文件如下:

...
kotlin {
    jvmToolchain(17)
}

android {
    namespace 'de.dthinking.app'
    compileSdkVersion 34

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = "17"
    }
  ...
}


执行**./gradlew --version**的输出如下:

------------------------------------------------------------
Gradle 8.0
------------------------------------------------------------

Build time:   2023-02-13 13:15:21 UTC
Revision:     62ab9b7c7f884426cf79fbedcf07658b2dbe9e97

Kotlin:       1.8.10
Groovy:       3.0.13
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17 (Oracle Corporation 17+35-LTS-2724)
OS:           Windows 10 10.0 amd64


其他解决方案调整了gradle设置,但在我的情况下没有显示:android studio overlay
我通过调整android/build.gradle让它工作:

allprojects {
    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
        kotlinOptions.jvmTarget = "1.8"
    }

    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KaptGenerateStubs).configureEach {
        kotlinOptions.jvmTarget = "1.8"
    }
}


当我将jvmTarget设置为“17”时,这不起作用,从一开始就发生了同样的错误。但我想使用版本17而不是1.8。我真的很感激解释为什么我对android/app/build.gradle的更改实际上什么也没做。还有其他文件需要调整吗?

00jrzges

00jrzges1#

我遇到了同样的问题,以下方法对我有效:
app/build.gradle中:

android {
    ...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlin {
        jvmToolchain(17)
    }
    ...
}

字符串
不需要在android/build.gradle中进行调整。希望这能有所帮助。

相关问题