my project's Gradle version is incompatible with the Java version that Flutter is using for Gradle
Asked Answered
E

5

8

I wanted to move my project into Android Studio and when I was running the simulator, the project was running fine. Since I updated Android Studio, the simulator has the error that the Gradle version of the project is not compatible with the Java version.

I would like to know how I can fix the problem gradle version of my project with version 6.8.3 and the compatible version of java version of my PC, I can't find the compatible version of Java with my project that it could work right I think, because of I upgraded my android studio with it upgraded Java too and I can't it downgrade again, I wish that you understood now.

Setup:

Gradle 6.8.3
Java 17
Flutter 3.7.12
Android Studio 2022.2.1

Error Message:

FAILURE: Build failed with an exception.
* What went wrong: Could not open settings generic class cache for settings file '.\android\settings.gradle' (.\.gradle\caches\6.8.3\scripts\9w4vzv9io97x5h1yfb63h0ld4).
 > BUG! exception in phase 'semantic analysis' in source unit 'BuildScript' Unsupported class file major version 61

To fix this issue, first, check the Java version used by Flutter by running flutter doctor --verbose. Then, update the Gradle version specified in .\android\gradle\wrapper\gradle-wrapper.properties to be compatible with that Java version.

Output from java --version:

java version "10.0.2" 2018-07-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)
Emeldaemelen answered 27/4, 2023 at 19:0 Comment(13)
It would be recommendable to mention the versions of the products you are using. And the errors. Have you tried changing the version of Gradle or Java to make them compatible? Have you read the requirements of each product?Variance
Yes, I tried changing the version of gradle and Java and it to downgrade but I couldn't fix it, every time came the same problem, if you have good intruction that I fix it, please write meEmeldaemelen
The version of gradle in project is 6.8.3 and the version of Java is 17Emeldaemelen
You need to provide the rest of the information to help others to help you. Versions of Flutter, Android Studio, etc, errors, configurations.Variance
Flutter version 3.7.12, Android Studio version flamingo 2022.2.1, FAILURE: Build failed with an exception. * What went wrong: Could not open settings generic class cache for settings file 'C:\Source\pizzaboy\android\settings.gradle' (C:\Users\Gholamreza\.gradle\caches\6.8.3\scripts\9w4vzv9io97x5h1yfb63h0ld4). > BUG! exception in phase 'semantic analysis' in source unit 'BuildScript' Unsupported class file major version 61Emeldaemelen
* 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 help.gradle.org BUILD FAILED in 1sEmeldaemelen
To fix this issue, first, check the Java version used by Flutter by running flutter doctor │ │ --verbose. │ │ │ │ Then, update the Gradle version specified in │ │ C:\Source\pizzaboy\android\gradle\wrapper\gradle-wrapper.properties to be compatible with that │ │ Java version. See the link below for more information on compatible Java/Gradle versions:Emeldaemelen
it has this problem just by this project because of gradle version and java versionEmeldaemelen
I wrote this command incmd for java -version and then java version "10.0.2" 2018-07-17 Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13) Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)Emeldaemelen
please write me how to change java version correctEmeldaemelen
Please edit your question and add the details in a way that's understandable. It is very difficult to track comments and they lack proper order and formatting.Variance
I would like to know how I can fix the problem gradle version of my project with version 6.8.3 and the compatible version of java version of my PC, I can't find the compatible version of Java with my project that it could work right I think, because of I upgraded my android studio with it upgraded Java too and I can't it downgrade again, I wish that you understood now.Emeldaemelen
Please edit your question to add the missing information from the comments.Variance
S
16

As you are using java 17, then upgrade gradle to version 7.3 at least. get idea from Compatibility Matrix. You can also get version idea from Gradle Release

Go to

  • Step 1: Go to the gradle directory for your project:

    cd android/gradle/wrapper

  • Step 2: Edit the gradle-wrapper.properties file to change the distribution Url field to the preferred Gradle version (7.3 or others):

    distributionUrl=https://services.gradle.org/distributions/gradle-7.6.1-all.zip

Happy Fixing!

Susette answered 1/6, 2023 at 16:33 Comment(1)
works like abaracadabraRetorsion
S
3

on your ide project explored Go to android->gradle(not .gradle)->wrapper->gradle-wrapper.properties

and change distribution to distributionUrl=https://services.gradle.org/distributions/gradle-7.6.1-all.zip

or you can change gradle-7.6.1-all to the latest gradle version

Simoom answered 30/12, 2023 at 13:4 Comment(0)
F
1

Change on latest gradle will work

distributionUrl=https://services.gradle.org/distributions/gradle-Latest version-all.zip

Example: distributionUrl=https://services.gradle.org/distributions/gradle-7.6.1-all.zip

Farmer answered 7/7, 2023 at 16:39 Comment(0)
M
0

sometimes Flutter is not recognizing your Java version and instead uses the one bundled with Android Studio

$ java --version
openjdk 17.0.12 2024-07-16
OpenJDK Runtime Environment (build 17.0.12+7-Ubuntu-1ubuntu224.04)
OpenJDK 64-Bit Server VM (build 17.0.12+7-Ubuntu-1ubuntu224.04, mixed mode, sharing)

$ echo $JAVA_HOME
/usr/lib/jvm/java-17-openjdk-amd64

$ flutter analyze --suggestions
Newer than known valid Java version (21.0.3), gradle (7.6.3).
 Treating as valid configuration.

┌───────────────────────────────────────────────────────────────────┐
│ General Info                                                      │
│ [✓] App Name: audio_flutter_app                                   │
│ [✓] Supported Platforms: android, ios                             │
│ [✓] Is Flutter Package: yes                                       │
│ [✓] Uses Material Design: yes                                     │
│ [✓] Is Plugin: no                                                 │
│ [✗] Java/Gradle/Android Gradle Plugin:                            │
│ Incompatible Java/Gradle versions.                                │
│ Java Version: 21.0.3, Gradle Version: 7.6.3                       │
│                                                                   │
│ See the link below for more information:                          │
│ https://docs.gradle.org/current/userguide/compatibility.html#java │

here the link how the flutter detect your java version

  /// This searches for Java in the following places, in order:
  ///
  /// 1. the runtime environment bundled with Android Studio;
  /// 2. the runtime environment found in the JAVA_HOME env variable, if set; or
  /// 3. the java binary found on PATH.

I uninstalled my android studio then it worked again, or try moving the Android Studio installation folder to a different location that Flutter cannot detect

$ flutter analyze --suggestions

┌───────────────────────────────────────────────────────────────────┐
│ General Info                                                      │
│ [✓] App Name: audio_flutter_app                                   │
│ [✓] Supported Platforms: android, ios                             │
│ [✓] Is Flutter Package: yes                                       │
│ [✓] Uses Material Design: yes                                     │
│ [✓] Is Plugin: no                                                 │
│ [✓] Java/Gradle/Android Gradle Plugin: compatible java/gradle/agp │
Manteau answered 6/10, 2024 at 10:13 Comment(0)
S
0

I recently faced this problem on my Ubuntu after updating my Android Studio to Ladybug. When I checked my Java version from terminal, it was returning OpenJDK version 11 and I updated my gradle version to 7.6.1 but it was not working.

Then I went to /home/user/android-studio/jbr/bin and open terminal in that folder and typed

./javac --version

after that my java version was showing 21. Then I went to this compatibility matrix website

https://docs.gradle.org/current/userguide/compatibility.html#java

and found 8.5 gradle version for Java 21. I updated my distribution url in android/gradle/wrapper/gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip

After that, my project is running successfully.

Smallish answered 6/10, 2024 at 11:58 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.