由于 JDK /compileOptions 导致 Flutter Android 构建失败

问题描述 投票:0回答:1

我正在构建一个 Flutter 应用程序并使用 Fastlane。在build.gradle文件中,添加了编译选项,如下所示:

android {
    namespace = "com.jasonholtdigital.mythicgme2e"
    compileSdk = 35
    ndkVersion = "27.1.12297006"

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

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_17
    }
//...
}

这些编译选项绝对会导致构建过程失败并出现异常:

* What went wrong:
Execution failed for task ':app:compileReleaseJavaWithJavac'.
> Could not resolve all files for configuration ':app:androidJdkImage'.
   > Failed to transform core-for-system-modules.jar to match attributes {artifactType=_internal_android_jdk_image, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
      > Execution failed for JdkImageTransform: /Users/jholt/Library/Android/sdk/platforms/android-35/core-for-system-modules.jar.
         > Error while executing process /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/jlink with arguments {--module-path /Users/jholt/.gradle/caches/transforms-3/122f621407d8450d48c3dc7c37f78808/transformed/output/temp/jmod --add-modules java.base --output /Users/jholt/.gradle/caches/transforms-3/122f621407d8450d48c3dc7c37f78808/transformed/output/jdkImage --disable-plugin system-modules}

* 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.

BUILD FAILED in 10s

无论我使用 flutter build aab、fastlane 还是 Android Studio 的典型构建方法进行发布构建,构建都会失败。调试构建工作并成功部署到物理设备。

当我删除这些行时,使用 flutter build aab 构建成功,但 fastlane 失败,并出现以下异常:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileReleaseKotlin'.
> Error while evaluating property 'compilerOptions.jvmTarget' of task ':app:compileReleaseKotlin'.
   > Failed to calculate the value of property 'jvmTarget'.
      > Unknown Kotlin JVM target: 21

谁能解释一下发生了什么事以及我该如何应对这种情况?我为此花费了一天的时间,从我的计算机中完全删除了所有 JDK/Android Studio 内容并重新安装。 JDK 总是会出现一些新问题。

android flutter build release fastlane
1个回答
0
投票

Unknown Kotlin JVM target: 21
看起来很奇怪。在您的配置中,您使用 Java 17。您可以尝试吗

kotlinOptions {
  jvmTarget = "17"
}

JavaVersion.VERSION_17.toString()

© www.soinside.com 2019 - 2024. All rights reserved.