133

I have installed Android Studio Canary 2020.3.1.22 and trying to run Flutter project on Apple Silicon(ARM) Mac. Unfortunately, it is giving me this error when I try to run default flutter counter app.

Here is the error I am getting:

Could not open settings generic class cache for settings file '/Users/khamidjonkhamidov/StudioProjects/dummy/android/settings.gradle' (/Users/khamidjonkhamidov/.gradle/caches/6.7/scripts/f0emg6u6oecmxqzgk5g9nn4ui).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 61

Gradle version: 6.7 but I tried 7+ JDK version 17

I would really appreciate your help)

Khamidjon Khamidov
  • 6,783
  • 6
  • 31
  • 62

31 Answers31

132

According to the official grade docs: Java 17 and later versions are not yet supported.

You can check compatibility here.

So I have installed Java11 from Azul.

p.s. don't forget to change jdk version in Android studio

Preferences -> Build -> Build Tools -> Gradle -> Gradle JDK

neberaa
  • 1,656
  • 2
  • 10
  • 9
30

Got the same error while I upgraded my build.gradle to Java 17. And the fix is as simple as we think:

Gradle starts supporting Java17 only from 7.3 release

Here's the complete reference for Java vs Gradle compatibility: https://docs.gradle.org/current/userguide/compatibility.html

Upgraded my gradle to 7.3 in gradle-wrapper.properties.

https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip

Some of you may experience now the Gradle dependency cache corrupt error after this like me. So better delete the gradle-wrapper.jar and reinstall it using the command:

./gradlew wrapper

Everything will work perfectly fine from here.

In case if you still face Gradle corrupt issue, please check whether you are using latest version of IDE especially Intellij.

ArunSelvam P M
  • 429
  • 5
  • 6
24

I faced this error when I updated my android studio

Solution:

you need to upgrade your distributionUrl According to the java version

‌Below is the Java version and Supported Gradle version

Faiz Ahmad Dae
  • 5,653
  • 2
  • 14
  • 19
  • 2
    Source of this compatibility table (for future release): https://docs.gradle.org/current/userguide/compatibility.html – Quentin CG Apr 03 '23 at 23:45
21

First, you can execute this command: /usr/libexec/java_home -V, to retrieve all installed jdsk:

[~]$ /usr/libexec/java_home -V

Matching Java Virtual Machines (4):
    17.0 (x86_64) "Oracle Corporation" - "OpenJDK 17.0" /Users/ciccio/Library/Java/JavaVirtualMachines/openjdk-17.0/Contents/Home
    14.0.1 (x86_64) "Oracle Corporation" - "OpenJDK 14.0.1" /Users/ciccio/Library/Java/JavaVirtualMachines/openjdk-14.0.1/Contents/Home
    11.0.12.1 (x86_64) "Amazon.com Inc." - "Amazon Corretto 11" /Users/ciccio/Library/Java/JavaVirtualMachines/corretto-11.0.12/Contents/Home
    10.0.2 (x86_64) "Oracle Corporation" - "Java SE 10.0.2" /Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home
    1.8.0_302 (x86_64) "Amazon" - "Amazon Corretto 8" /Users/ciccio/Library/Java/JavaVirtualMachines/corretto-1.8.0_302/Contents/Home

Now, imagine you want to remove the version 17:

[~]$ java -version
openjdk version "17" 2021-09-14
OpenJDK Runtime Environment Homebrew (build 17+0)
OpenJDK 64-Bit Server VM Homebrew (build 17+0, mixed mode, sharing)

Go into the path of the version you want to remove (in this case "/Users/ciccio/Library/Java/JavaVirtualMachines/openjdk-17.0/Contents/Home"), and delete entire folder: "/Users/ciccio/Library/Java/JavaVirtualMachines/openjdk-17.0".

Once removed, go back on terminal and use:

[~]$ /usr/libexec/java_home -v 14.0.1 --exec javac -version
javac 14.0.1

to force the new version to use (14.0.1).

Next check if is correct:

[~]$ java -version
openjdk version "14.0.1" 2020-04-14
OpenJDK Runtime Environment (build 14.0.1+7)
OpenJDK 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)
[~]$

Your Gradle now is back to work.

elp
  • 8,021
  • 7
  • 61
  • 120
20

Happened with newly created Flutter app in 2023 January with Mac Mini M1. If you have another working Flutter apps do not downgrade or update Java version as it will cause problem with all other working ones. Find gradle-wrapper.properities file inside gradle/wrapper folder (directly inside Android folder) and check gradle version. You just need to use newer version of gradle. I replaced this one and used flutter run command from terminal and it worked:

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

With this one:

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

No need to do anything else. Version number may be different for you depending on when you are trying this and what Java version you have.

Note: Same fix also effective for another error message as well stating version 63:

BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 63
Elmar
  • 2,235
  • 24
  • 22
14

Basically, I installed jdk using brew install java which was not compatible with my current gradle I guess. So

  1. I uninstalled java first using: brew uninstall java
  2. installed JDK 8 or JDK 11 from azul.
  3. Installed gradle: gradle-6.9-all.zip

When done, everything worked smoothly.

Hamed
  • 5,867
  • 4
  • 32
  • 56
Khamidjon Khamidov
  • 6,783
  • 6
  • 31
  • 62
8

I found a way to fix this error without messing with the locally installed Java version or Gradle. Here is what I did:

  1. If you are developing a Flutter project and got this error, go to File -> Close Project.
  2. Then re-open from the android folder (omit this if you received from a pure Android project).
  3. Now, Gradle may detect the issue on its own, and it will take a while to check. After it is done, it may provide upgrade steps in an upgrade assistant window at the bottom of the window along with logcat, build, terminal etc… which you need to accept and tell it to execute. Once it finishes, the error is resolved, and you are good to go.
  4. If it does not seem to do anything on its own, then please open the Project Structure tab. Now select the latest Gradle version available that does not contain -rc (you don't want these, most of the time they are not stable releases).
  5. Now select the JDK version that Gradle uses by going to Gradle (sidebar on the right of the window) -> Wrench Icon -> Gradle Settings. Select a compatible JDK version according to the Gradle project's documentation, as found HERE. Current latest stable version of Gradle is 7.4 with maximum supported JDK version 17 (also latest I believe if you use something like openJDK which I use), but Android Studio version at 7.1 so be careful.

Tested on MacBook Air M1 running macOS Monterey 12.2.1.

8

Finally I Got the Solution

It is very easy to solve

step 1 : select the gradle version which support your java version link

step 2 : open your project navigate to your_project_name/android/gradle/wrapper/gradle-wrapper.properties

step 3 : in distributionUrl change the gradle version according to your java version

That's it No need to install older java versions

Happy coding

S K
  • 81
  • 1
  • 2
  • 1
    While this information may be helpful, consider editing the formatting of your post (use the built in list format) and remove unnecessary comments like "Finally I got the Solution" and "it is very easy to solve as these tend to serve as spam and distract from the real information in your answer. – Slight Feb 26 '23 at 17:08
  • 1
    Good stuff, just updating it from 7.5 to 7.6 to work with java 19, did the trick! – Artokun Mar 06 '23 at 00:10
5

Check currently active java version:-

javac -version

If it is greater than 11 downgrade it to 11 or 8. Check your available java jdk version installed:-

/usr/libexec/java_home -V

If java 11 or 8 is not installed first install one of them using this link:- Download jdk 8

then change the default java version in .bash_profile

Edit .bash_profile

sudo nano ~/.bash_profile

Add 1.8 or 11 as default. (Add below line to bash_profile file)

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)

OR

export JAVA_HOME=$(/usr/libexec/java_home -v 11)

Now Press CTRL+X to exit the bash. Press 'Y' to save changes. And reload bash_profile

source ~/.bash_profile

Pawan Verma
  • 1,152
  • 14
  • 22
5

In my case I had this set

Typing flutter --version on terminal:

Flutter 3.7.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision c07f788888 (10 weeks ago) • 2023-02-22 17:52:33 -0600
Engine • revision 0f359063c4
Tools • Dart 2.19.2 • DevTools 2.20.1

Typing javac -version on terminal to get you java version:

javac 19.0.2

So, by this grade compatibility matrix I had to update my project/android/gradle/wrapper/gradle-wrapper.properties distributionUrl to:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
M. Massula
  • 3,730
  • 2
  • 11
  • 14
2

Windows Users

Open Android Studio and Click on Setting ICON far right. And Go to Project Structure Option and select the SDK's Version 11.0.15 and click apply than on the left side click on Module Option and select Module SDK's options and select Project SDK 11. and at the bottom at Project Settings CLICK on SDK and select on 11 SDK versions. It will give you the JDK path

C:\Program Files\Android\Android Studio\jbr

Copy this path and Open the System Environment Variable Create a New JAVA_HOME path with the location Image

and click OK and save everything Now run your app in ANDROID STUDIO and ENJOY!

Ayoub Ali
  • 91
  • 1
  • 4
2

System: Mac M1, Android Studio Electric Eel (2022.1.1 Patch 1), JDK 19.02

I encountered this error when created a fresh project using flutter create and tried to run it in Android Studio.

Now I've got an interesting solution that worked for me:

  1. Open the flutter project in Android Studio
  2. Open build.gradle, the one under android folder
  3. On the top right it shows "Open for Editing in Android Studio" (although it's already in Android Studio!). Click on that to open it for editing. I opened it in another window, but doesn't matter.
  4. It starts to automatically download and update gradle to sync the build file. At one point, tt might also prompt you to upgrade gradle, which is good to do.
  5. Done! Close the build.gradle and re-run the project. It should build and run fine.
Mahm00d
  • 3,881
  • 8
  • 44
  • 83
1

SOLUTION:

go to android/gradle/wrapper/gradle-wrapper.properties

Find the distributionUrl variable and change the end path to gradle-7.6-all.zip

tk_tanz
  • 384
  • 2
  • 7
1

Error

Could not open settings generic class cache for settings file '/Users/khamidjonkhamidov/StudioProjects/dummy/android/settings.gradle' (/Users/khamidjonkhamidov/.gradle/caches/6.7/scripts/f0emg6u6oecmxqzgk5g9nn4ui).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 64

Steps To Solve :

1- open the gradle prodperties see the current project gradle example "gradle-7.4"

2- open compatibility see https://docs.gradle.org/current/userguide/compatibility.html

3- download java version, in ower example java 17 https://www.oracle.com/java/technologies/downloads/

Abdallah Mahmoud
  • 491
  • 1
  • 5
  • 8
1

I was trying to clone a Flutter project from GitHub that was working perfectly until the last commit and push. After deleting it locally and cloning it again, I encountered an error when opening it in Android Studio.

Solution:

Open the Android module of the Flutter project in Android Studio.

Set the Gradle JDK to zulu-17 by going to Settings > Build, Execution, Deployment > Gradle. In my case, the Gradle Plugin Version was 7.2.01, which can be found in File > Project Structure > Project. Check the Gradle documentation to find the compatible JDK versions for your Gradle version. https://docs.gradle.org/current/userguide/compatibility.html

Run java -version in the Flutter project's terminal window. In my case, it showed a different Java version than zulu-17.

Set the JDK path in the .zshrc file located at /Users/homepathname/.zshrc:

export JAVA_HOME="/Users/homepathname/Library/Java/JavaVirtualMachines/azul-17.0.7/Contents/Home"
export PATH=$JAVA_HOME/bin:$PATH

Open a new terminal window in the Flutter project and run java -version again. This should show the same Java version as the Gradle JDK.

The project should now run without any problems.

This solution worked for me as it synchronized the Java versions used by Gradle and the terminal.

Lins Louis
  • 2,393
  • 2
  • 25
  • 30
0

I had this issue when I set the target for a new IntelliJ Kotlin project to be Java 17. My fix was to:

  • set the target to 9 in build.gradle.kt
  • close the project
  • delete the .gradle and .idea directories from the project folder
  • remove the project from the recent projects list
  • open the gradle file from IntelliJ and get it to rebuild everything
Tim Lavers
  • 11
  • 2
0

Open the Gradle settings and change the Gradle JVM to the same JDK version you are using. (I am using 14.0.2) This worked for me.

0

I had that Issue creating Projects from IntelliJ. It seems the issue was the Gradle JVM Version.

Here is a configuration that works:

System: Mac with ARM, Mac OS 12.1, M1 Max

  • java version 18.0.1-zulu
  • kotlin version 1.7.0
  • gradle version 7.5

I installed those version with sdkman https://sdkman.io/ and set the config manually on intellij (See attached Screenshot for Details)

IntelliJ Gradle JVM config

Alej Kun
  • 1
  • 1
0

My solution was to open the android project in Android Studio. It detected the needed Gradle update and performed the update upon command.

Jim T
  • 2,480
  • 22
  • 21
0

I can't speak for everyone, but for me, I went into Flutter project's file android/gradle/gradle.properties, and changed the org.gradle.java.home value so that it pointed to a folder containing JDK 11 instead of JDK 18. That way, it used a JDK version that was actually supported.

Max
  • 147
  • 1
  • 14
0

Giving my two seconds here... In my case, I could fix it by finding my gradle version in the file gradle.wrapper.properties and checking the compatibility with the JDK, so I needed to install the JDK 16, so in my build.gradle(:app) I put this line of code inside the android {} :

compileOptions {
   sourceCompatibility JavaVersion.VERSION_16
   targetCompatibility JavaVersion.VERSION_16
}

After this I build my android version again, and it worked.

0

On my side I fixed this issue by setting the default Java Version to 8 (download it if needed)

Mac:

  1. Open Terminal.
  2. open ~/.bash_profile
  3. Add
# SWITCH TO JAVA VERSION 8
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
  1. Save and restart Android Studio.
Yasser AKBBACH
  • 539
  • 5
  • 7
0

I ran into this issue on VSCode+Mac using the Gradle for Java extension.

My project uses Java 17 but Gradle was using JDK19, which I also had installed. I removed the jdk-19.jdk folder from /Library/Java/JavaVirtualMachines and then ran the "Clean Java Language Server Workspace" task in VSCode.

After that, Gradle successfully built and I was even able to put the jdk-19 folder back and things continued to work.

Lucian Thorr
  • 1,997
  • 1
  • 21
  • 29
0

Changing the Java Version in the Intellij resolved the issue. enter image description here

vinay shetty
  • 895
  • 1
  • 9
  • 15
0

Easy fix in 2023:

  1. Command in the terminal:

    export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)

  2. Check classpath, current working one:

    classpath 'com.android.tools.build:gradle:7.1.2'

  3. Check gradle-wrapper.properities file:

     distributionBase=GRADLE_USER_HOME
     distributionPath=wrapper/dists
     zipStoreBase=GRADLE_USER_HOME
     zipStorePath=wrapper/dists
    distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
    
  4. If still not solved you need to change Gradle JDK from inside Android Studio like below.

enter image description here

After that you can run fluter app directly from terminal without any issue. Note: Android Studio default JDK (11.0.15) does not work and causes this issue. Azul Zulu 16.0.2 works and solves the issue.

Gk Mohammad Emon
  • 6,084
  • 3
  • 42
  • 42
Elmar
  • 2,235
  • 24
  • 22
0

In my case, I use the react native cli and my android gradle is 7.3.1. I open the android folder in the android folder in the android studio and it suggests my gradle once after degradation it works fine

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 12 '23 at 02:58
0

Context: Flutter, Mac M1, Java 19.0.2

Problem occured on following command:

flutter build apk

I just installed (reintalled) gradle via homebrew like this:

brew install gradle

I suppose it was related to my recent upgrade (Java was upgraded to OpenJDK Temurin 19.0.2).

I also noticed that flutter command was trying to use gradle 7.4 (the only one gradle version installed before). As previously mentioned by others, there has to be consistency between your Java version and gradle version according to Gradle Official Compatibility Matrix.

Please, verify it with following commands:

java -version
gradle -version

I think this process / solution can be applicable in general. Hope it helps!

Tomas Zubrik
  • 347
  • 3
  • 11
0

This problem can be solve by cleaning and upgrading the flutter project use these command on your terminal

--> flutter clean then run --> flutter upgrade

Sumit Ojha
  • 283
  • 2
  • 8
0

Usually, this bug relates to the incompatibility of the gradle version and the JDK version.

if you want to be sure. first check this for compatibility.

if this is your problem. find your version in this, then rename your version in gradle-wrapper.properties of your project.

Bashid
  • 433
  • 5
  • 15
0

FYI I was seeing this b/c in Egypt, ISPs often block jsdelivr :(

Here's a related issue: https://github.com/CocoaPods/CocoaPods/issues/11939#issuecomment-1582406310

So I installed & ran Nord VPN, re-ran pod install, good to go

starball
  • 20,030
  • 7
  • 43
  • 238
Blundering Philosopher
  • 6,245
  • 2
  • 43
  • 59
0

I resolved the issue by changing the gradle version compatible with my java version. My java version I am using is: 20.0.1

Changed the distributionUrl to use gradle 8.1, Go in the folder: /android/gradle/wrapper/gradle-wrapper.properties

Change the distributionUrl: distributionUrl=https://services.gradle.org/distributions/gradle-8.1-all.zip

Shivam Bhatia
  • 62
  • 1
  • 5