33

System Settings:

  • MacOS Ventura

  • Android Studio Electric Eel

I am installing Flutter on my Intel Mac.

After Running flutter doctor

The outcome is this:

[✓] Flutter (Channel stable, 3.7.0, on macOS 13.2 22D49 darwin-x64, locale
    en-MX)
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for
      more details.
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.1)
[✓] VS Code (version 1.74.3)
[✓] Connected device (2 available)
[✓] HTTP Host Availability

and after running flutter doctor --android-licenses the outcome is this:

Exception in thread "main" java.lang.UnsupportedClassVersionError: 
com/android/prefs/AndroidLocationsProvider 
has been compiled by a more recent version of the Java Runtime (class file version 55.0),
this version of the Java Runtime only recognizes class file versions up to 52.0

I installed Java for Mac from this link on January 2023 from Here

Has someone encountered the same error? How did you fix it?

Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
Pasdian
  • 489
  • 1
  • 4
  • 7

9 Answers9

37

I will try to give a more detailed solution:

  1. Install the latest version of the Java SDK from this link
  2. Pick Java 19 and the x64 DMG Installer (this worked for me)
  3. Follow the installation instructions.
  4. [optional] If necessary, set your JAVA_HOME path following these instructions (mac)
  5. Test the installation by running flutter doctor --android-licenses
Tomas Ward
  • 854
  • 6
  • 23
  • 3
    This worked for me, but using `Arm 64 DMG Installer` for a latest Mac with M1 silicon chip. – JD_dev Jan 30 '23 at 19:12
  • This worked for me! Just needed to update from Java 8 to Java 19 on Linux. I used sdkman and it worked just as well: `sdk install java 19.0.2-oracle` – jxc Mar 10 '23 at 17:22
  • This https://github.com/flutter/flutter/issues/120388#issuecomment-1425196389 worked for me – lauWM Apr 10 '23 at 15:46
  • 1
    oh, dude, you save my day, thank you – angwrk Jun 08 '23 at 15:50
12

For Windows

  1. Download and Install latest JDK from [Java SE Development Kit 19.0.2][1]

  2. Set a system variable as

    Variable Name: JAVA_HOME

    Variable Value: C:\Program Files\Java\jdk-19

  3. Add a path variable name as %JAVA_HOME%\bin

  4. Now run flutter doctor

Hope, it will solve. [1]: https://www.oracle.com/java/technologies/downloads/#jdk19-windows

abdullah_bd
  • 484
  • 3
  • 12
6

While installing the JDK by Oracle download works, best way to make sure that you have the correct version on MacOS is to install JDK using Homebrew (If you don't have Homebrew, Installation instructions: https://docs.brew.sh/Installation). Also, keeping it up-to-date is a lot easier this way.

brew install openjdk

If you have other OpenJDK versions installed, you may need to link this correct one:

brew link --force openjdk@19

To make it the default for your shell, add the following lines to ~/.zshrc:

export JAVA_HOME="/opt/homebrew/opt/openjdk"
export PATH="$JAVA_HOME/bin:$PATH"

And then:

source ~/.zshrc

You only need to do this once.

Then rerun: flutter doctor --android-licenses

Juha Kervinen
  • 332
  • 1
  • 5
1

Additionally from what Tomas Ward said about installing the lastest SDK, for windows I found this for adding the JAVA_HOME to the path. Hope it helps.

Napo
  • 533
  • 1
  • 5
  • 13
0

Found the solution.

I needed to update the JDK from here.

Pasdian
  • 489
  • 1
  • 4
  • 7
  • 1
    Can you [edit] your answer to specify what version you upgraded from an to? That will make this answer more valuable in the future, for people experiencing a similar issue, in terms of isolating whether they're experiencing the same problem, or if your solution is still relevant to them. – Jeremy Caney Jan 25 '23 at 22:43
0

I have uninstalled. JRE Java runtime environment and it works.

0

Yeah @Tomas Ward solution is worked For me. But Let me add some more details For the Windows users.

  1. As @Tomas says We need to download Java SE Development Kit 19.0.2 First of all Click On This Link To Download Java SE Development Kit 19.0.2.
  2. Then Download x64 Installer OR x64 MSI Installer Then Install Java SE Development Kit In Your System.
  3. Now You need to Set OR Update This New Java SE Development Kit Path into Your JAVA_HOME Path.

And As You Set/Update JAVA_HOME Path Your Error will resolved.

0

I tested a higher version (jdk17) and successfully executed it. But I don't think this is a good idea. Let's wait for the official solution

yangz
  • 1
  • Hi, and thanks for joining Stack Overflow. Please do not leave an "Answer" unless it addresses solving the problem. Short messages similar to this one should rather be left as a comment under the question. – John Leuenhagen Feb 28 '23 at 00:28
0

None of these answers worked for me. So I finally bit the bullet and switched over to asdf. It's worth it and will save you so much trouble in the future.

  1. asdf install java adoptopenjdk-19.0.0+36
  2. asdf global java adoptopenjdk-19.0.0+36
  3. Do what this comment suggests and add this to your .zshrc
    # set JAVA_HOME on every change directory
    function asdf_update_java_home {
      asdf current java 2>&1 > /dev/null
      if [[ "$?" -eq 0 ]]
      then
          export JAVA_HOME=$(asdf where java)
      fi
    }
    
    precmd() { asdf_update_java_home; }
    # end set JAVA_HOME
    
  4. exec zsh # reloads current terminal to use changed .zshrc
  5. echo $JAVA_HOME should show asdf directory one
  6. flutter doctor --android-licenses

Machine details

  • Macbook Pro M1
  • ZSH as my shell
Kyle Venn
  • 4,597
  • 27
  • 41