简体   繁体   中英

UnsupportedClassVersionError while 'flutter doctor --android-licenses' MacOS

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?

Thanks.

Found the solution.

I needed to update the JDK from here .

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

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.

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.

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM