1

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.

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks this is one thing I was trying to figure out. I couldn’t find out where it was expecting the different versions after I changed it in the apps build grader.
Yes this was frustrating issue when this error come to me at first. So it's work well or you still have a problem?
It ended up not solving the problem for me.
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()

2 Comments

I didn't try this but appreciate the help. For some reason all the files using the JDK are out of sync in my app.
I tried this and I think it solved another issue that was popping up about using the wrong JVM version for Kotlin.
1

I solved the problem and got the app to build with this:

java {
        toolchain {
            languageVersion = JavaLanguageVersion.of(17)
        }
    }

Added to my app's build.gradle after the compileOptions and kotlinOptions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.