'flutter doctor --android-licenses' MacOS 时出现 UnsupportedClassVersionError

Pas*_*ian 37 macos mobile android flutter

系统设置:

\n
    \n
  • MacOS 文图拉

    \n
  • \n
  • Android Studio 电鳗

    \n
  • \n
\n

我正在我的 Intel Mac 上安装 Flutter。

\n

跑步后flutter doctor

\n

结果是这样的:

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

运行后flutter doctor --android-licenses结果是这样的:

\n
Exception in thread "main" java.lang.UnsupportedClassVersionError: \ncom/android/prefs/AndroidLocationsProvider \nhas been compiled by a more recent version of the Java Runtime (class file version 55.0),\nthis version of the Java Runtime only recognizes class file versions up to 52.0\n
Run Code Online (Sandbox Code Playgroud)\n

我于 2023 年 1 月从这里通过此链接安装了 Java for Mac

\n

有人遇到过同样的错误吗?你怎么修好它的?

\n

Tom*_*ard 39

我将尝试给出更详细的解决方案:

  1. 从此链接安装最新版本的 Java SDK
  2. 选择 Java 19 和x64 DMG Installer(这对我有用)
  3. 按照安装说明进行操作。
  4. [可选] 如有必要,请JAVA_HOME按照以下说明设置路径(mac)
  5. 通过运行测试安装flutter doctor --android-licenses

  • 这对我有用,但使用“Arm 64 DMG Installer”用于带有 M1 硅芯片的最新 Mac。 (3认同)

abd*_*_bd 13

对于 Windows

  1. 从 [Java SE Development Kit 19.0.2][1] 下载并安装最新的 JDK

  2. 将系统变量设置为

    变量名:JAVA_HOME

    变量值:C:\Program Files\Java\jdk-19

  3. 添加路径变量名称为%JAVA_HOME%\bin

  4. 现在运行flutter doctor

希望,它会解决。[1]: https: //www.oracle.com/java/technologies/downloads/#jdk19-windows


Juh*_*nen 6

虽然可以通过 Oracle 下载安装 JDK,但确保您在 MacOS 上拥有正确版本的最佳方法是使用 Homebrew 安装 JDK(如果您没有 Homebrew,安装说明: https: //docs.brew.sh/安装)。此外,通过这种方式保持最新状态要容易得多。

brew install openjdk
Run Code Online (Sandbox Code Playgroud)

如果您安装了其他 OpenJDK 版本,您可能需要链接这个正确的版本:

brew link --force openjdk@19
Run Code Online (Sandbox Code Playgroud)

要使其成为 shell 的默认值,请将以下行添加到 ~/.zshrc:

export JAVA_HOME="/opt/homebrew/opt/openjdk"
export PATH="$JAVA_HOME/bin:$PATH"
Run Code Online (Sandbox Code Playgroud)

进而:

source ~/.zshrc
Run Code Online (Sandbox Code Playgroud)

您只需执行一次此操作。

然后重新运行:flutter doctor --android-licenses