解决运行flutter doctor --android-licenses时报错

问题描述:

配置flutter环境时,会使用flutter doctor命令来检查运行flutter的相关依赖是否配好。能看到还差 Android license status unknown.未解决。

复制代码
C:\Users\ipkiss.wu>flutter doctor
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.10.6, on Microsoft Windows [版本 10.0.19043.2006], locale zh-CN)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[!] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[√] Chrome - develop for the web
[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components
[√] Android Studio (version 2022.2)
[√] VS Code
[√] Connected device (3 available)
[√] Network resources

! Doctor found issues in 2 categories.

在运行命令 flutter doctor --android-licenses 时报错

复制代码
Microsoft Windows [版本 10.0.19043.2006]
(c) Microsoft Corporation。保留所有权利。

C:\Users\ipkiss.wu>flutter doctor --android-licenses
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/android/sdklib/tool/sdkmanager/SdkManagerCli has been compiled by a more recent version of the Java Runtime (class file version 61.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:756)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
        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:418)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:632)
Android sdkmanager tool was found, but failed to run
(C:\Users\ipkiss.wu\AppData\Local\Android\sdk\cmdline-tools\latest\bin\sdkmanager.bat): "exited code 1".
Try re-installing or updating your Android SDK,
visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions.

C:\Users\ipkiss.wu>

主要问题:

has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0

翻译:已由较新版本的Java运行时(类文件版本61.0)编译,此版本的Java运行时仅识别类文件版本52.0

因为我安装的flutter是最新版本的,而JDK是1.8版本,大胆猜测是jdk版本不兼容的问题。

复制代码
C:\Users\ipkiss.wu>flutter --version
Flutter 3.10.6 • channel unknown • unknown source
Framework • revision f468f3366c (3 weeks ago) • 2023-07-12 15:19:05 -0700
Engine • revision cdbeda788a
Tools • Dart 3.0.6 • DevTools 2.23.1

尝试:

卸载JDK8安装JDK11

复制代码
Microsoft Windows [版本 10.0.19043.2006]
(c) Microsoft Corporation。保留所有权利。

C:\Users\ipkiss.wu>java -version
java version "11.0.20" 2023-07-18 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.20+9-LTS-256)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.20+9-LTS-256, mixed mode)

C:\Users\ipkiss.wu>flutter doctor --android-licenses
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
:  com.android.sdklib.tool.sdkmanager.SdkManagerCli ʱ LinkageError
        java.lang.UnsupportedClassVersionError: com/android/sdklib/tool/sdkmanager/SdkManagerCli has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
Android sdkmanager tool was found, but failed to run
(C:\Users\ipkiss.wu\AppData\Local\Android\sdk\cmdline-tools\latest\bin\sdkmanager.bat): "exited code 1".
Try re-installing or updating your Android SDK,
visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions.

C:\Users\ipkiss.wu>

在安装jdk11 之后还是报错,但信息不一样,这次显示的版本是从55到61

推断jkd11(55) jdk17(61)

解决办法:

安装jdk17

相关推荐
h***34638 分钟前
MS SQL Server 实战 排查多列之间的值是否重复
android·前端·后端
用户693717500138412 分钟前
16.Kotlin 类:类的形态(三):密封类 (Sealed Class)
android·后端·kotlin
摆烂积极分子2 小时前
安卓开发学习-安卓版本
android·学习
谢斯3 小时前
编译AppFlowy
flutter
n***26564 小时前
MySQL JSON数据类型全解析(JSON datatype and functions)
android·mysql·json
t***82114 小时前
mysql的主从配置
android·mysql·adb
灰灰勇闯IT5 小时前
Flutter×鸿蒙深度融合指南:从跨端适配到分布式能力落地(2025最新实战)
分布式·flutter·harmonyos
YF02116 小时前
Frida如何稳定连接PC端跟Android手机端
android·mac·xposed
x.Jessica6 小时前
关于Flutter在Windows上开发的基本配置时遇到的问题及解决方法
windows·flutter
名字被你们想完了6 小时前
flutter 封装一个 tab
flutter