androidflutterbuildreleasefastlane

Failing Flutter Android Build Because of JDK / compileOptions


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.


Solution

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