flutter doctor -v 出现Android license status unknown,Run flutter doctor --android-licenses
to accept the SDK licenses.
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
• Android SDK at /Users/chris/development/sdk
• Platform android-33, build-tools 33.0.2
• ANDROID_HOME = /Users/chris/development/sdk
• Java binary at: /Users/chris/development/jdk/jre1.8.0_202.jre/Contents/Home/bin/java
• Java version Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
✗ 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.
flutter doctor --android-licenses出现
Error: A JNI error has occurred, please check your installation and try again
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
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Android sdkmanager tool was found, but failed to run
(/Users/chris/development/sdk/cmdline-tools/latest/bin/sdkmanager): "exited code 1".
Try re-installing or updating your Android SDK,
visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions.
问题出在 Java 版本上。错误提示中提到了 "this version of the Java Runtime only recognizes class file versions up to 52.0",说明您当前的 Java 版本太低,无法识别 class 文件的版本。
为了解决此问题,您需要安装更高版本的 Java,建议使用 Java 11。
我本地有高版本,直接选择了
重新运行 flutter doctor --android-licenses 并接受许可协议。
在出现的提示中,逐一阅读许可协议,并接受它们。您可能需要输入 "y" 并按 Enter 键来接受许可协议。
运行 flutter doctor -v 以验证问题是否已解决。