解决flutter doctor出现Android license status unknown或cmdline-tools component is missing

本文讲述了开发者在使用Flutter进行环境检查时遇到的Android SDK问题,包括`cmdline-tools`组件缺失和Java异常。通过在Android Studio中安装SDK命令行工具并接受许可,成功解决了这些问题,确保了开发环境的完整。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题描述

使用flutter doctor检查开发环境,出现以下问题

wangyangyangdeMacBook-Pro:~ wangyang$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[] Flutter (Channel stable, 2.2.1, on Mac OS X 10.15.7 19H2 darwin-x64, locale
    zh-Hans-US)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
	X cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ 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
[] Chrome - develop for the web
[] Android Studio (version 4.2)
[] VS Code (version 1.61.0)
[] Connected device (2 available)

! Doctor found issues in 1 category.

根据错误提示运行flutter doctor --android-licenses,出现以下Java异常。

wangyangyangdeMacBook-Pro:~ wangyang$ flutter doctor --android-licenses
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
	at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
	at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
	at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
	at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)
	at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	... 5 more

虽然这个错误不影响在Android上的编译和运行,但是本人是个强迫症,必须消灭掉!!!

解决方案

根据上面的错误显示,猜测难道是Android SDK的问题?

打开Android Studio, Preferences-Appearance & Behavior- System Settings- Android SDK-SDK Tools

发现SDK的命令行工具没有安装。
在这里插入图片描述

勾选,然后选择Apply,会出现安装提示.

在这里插入图片描述
点击OK,会出现安装进度。

在这里插入图片描述

安装完成后,再次运行flutter doctor,已经没有错误了。OK 完美!

wangyangyangdeMacBook-Pro:~ wangyang$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[] Flutter (Channel stable, 2.2.1, on Mac OS X 10.15.7 19H2 darwin-x64, locale
    zh-Hans-US)
[] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[] Xcode - develop for iOS and macOS
[] Chrome - develop for the web
[] Android Studio (version 4.2)
[] VS Code (version 1.61.0)
[] Connected device (2 available)

• No issues found!
Flutter assets will be downloaded from https://storage.googleapis.com. Make sure you trust this source! Doctor summary (to see all details, run flutter doctor -v): [☠] Flutter (the doctor check crashed) X Due to an error, the doctor check did not complete. If the error message below is not helpful, please let us know about this issue at https://github.com/flutter/flutter/issues. X Error: Cannot find the executable for `where`. This can happen if the System32 folder (e.g. C:\Windows\System32 ) is removed from the PATH environment variable. Ensure that this is present and then try again after restarting the terminal and/or IDE. [√] Windows Version (Windows 10) [!] Android toolchain - develop for Android devices (Android SDK version 35.0.1) X cmdline-tools component is missing Run `path/to/sdkmanager --install "cmdline-tools;latest"` See https://developer.android.com/studio/command-line for more details. X Android license status unknown. Run `flutter doctor --android-licenses` to accept the SDK licenses. See https://flutter.dev/to/windows-android-setup for more details. [X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe) ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable. [X] Visual Studio - develop Windows apps X Visual Studio not installed; this is necessary to develop Windows apps. Download at https://visualstudio.microsoft.com/downloads/. Please install the "Desktop development with C++" workload, including all of its default components [√] Android Studio (version 2024.3) [√] VS Code (version 1.98.1) [√] Connected device (1 available) [√] Network resources ! Doctor found issues in 4 categories.
03-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值