I have installed JDK jdk-23_windows-x64_bin and trying to run Flutter project on Windows computer. Unfortunately, it is giving me this error when I try to build the flutter apk.
Here is the error I am getting:
FAILURE: Build failed with an exception.
- What went wrong:
Could not open settings generic class cache for settings file ‘K:Mobile Appiposiposandroidsettings.gradle’ (C:Usersdev.gradlecaches7.4scriptsea4ydi90mwjg9g63m7r6nimmx).
BUG! exception in phase ‘semantic analysis’ in source unit ‘BuildScript‘ Unsupported class file major version 67
- 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.
BUILD FAILED in 3s
Running Gradle task ‘assembleRelease’… 5.8s
Gradle task assembleRelease failed with exit code 1
I tried JDK version jdk-11.0.24_windows-x64_bin.exe
2
Answers
Jdk-23 will not work. Try jdk17 or jdk11 of jetbrains (android studio). (You can use any alternative of these java version)
Further more:
1- Clean flutter and generated build files in your projects android side.
If it does not work then:
1-Update your flutter version, dart version and your .yaml dependencies.
2- Clean flutter and generated build files in your projects android side.
If it does not work and you have not done gradle migration:
1-You should change settings.gradle, build build.gradle and app build.gradle according to documentation. https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply
( Alternatively you can update your (1)android studio and (2)flutter plugin of android studio to create a new flutter project. (3)Then compare files that I stated. ( java and kotlin versions stated in documentation))
2- Clean flutter and generated build files in your projects android side.
You encountering the exception,
because Java 23 is not compatible with your development setup.
I encountered that exception a few days ago; it works for me by downloading and using Java 17 JDK for Windows from Oracle Java SE 17 Archive Download
After downloading and installing, I updated my PATH and JAVA_HOME, where my newly installed Java 17 is located. It is important to tell your Flutter project to use Java 17 JDK and other Java tools.
Also, I followed Deprecated imperative apply of Flutter’s Gradle plugins configurations.
The most complicated part is that you have to align your project with Gradle Compatibility Matrix, which you need to ensure that you are using a compatible Kotlin version, the Gradle version, which is based on Java 17 that you’re using.
Make sure that you’re using the latest version of Flutter and considering an updated environment for development (from which I agree with @Bunyamin Basoglu).
After you configure the required setup,
If you find it necessary, perform gradle cache clearing such as (note that you need to
cd android
to use ./gradlew commands in your terminal)and/or
flutter clean
.Then rebuild your project.
If the issue persists (or there is another exception),
Try these debugging techniques to understand which specific dependencies and packages that introduce the issue:
To learn more about debugging techniques: read here.
TIPS: Sometimes, Gradle causes the issue, so again, you need to understand the compatibility matrix to ensure that your project development setup is properly configured.
I hope it helps!