skip to Main Content

I’m building a Flutter app and using Fastlane. In the build.gradle file, compile options were added like this:

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
    }
//...
}

These compile options absolutely cause the build process to fail with an exception:

* 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

The build fails whether I use flutter build aab, fastlane, or Android Studio’s typical build methods for release builds. Debug builds work and successfully deploy to a physical device.

When I remove those lines, the build is successful using flutter build aab but fastlane fails with the following exception:

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

Can anyone explain what’s going on and how can I navigate this situation? I’ve burned a day on this, completely removing all JDK/Android Studio stuff from my computer and reinstalling. There’s always some new issue cropping up with the JDk.

2

Answers


  1. Unknown Kotlin JVM target: 21 looks strange. In your config you use Java 17. Can you try

    kotlinOptions {
      jvmTarget = "17"
    }
    

    or JavaVersion.VERSION_17.toString()

    Login or Signup to reply.
  2. You can see in this gradle discussion it’s the same error log as you. This error caused by your gradle version not compatible with your java version. You need to check the Compability Matrix of java, gradle, and kotlin.

    First check your java version:

    java -version
    

    Then you can check your gradle version in $flutterprojectroot/android/gradle/wrapper/gradle-wrapper

    Gradle version

    distributionUrl is pointing your gradle version.

    And you can see kotlin & android gradle version in android/settings.gradle in plugin section.

    settings.gradle

    *In older flutter project your kotlin version will be in android/build.gradle in buildscript section.

    Then sync all version based on the compability matrix.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search