flutter doctor 报错Android license status unknown. Run `flutter doctor --android-licenses` to...

使用flutter 时,运行flutter doctor,报错如下:
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.2.2, on macOS 11.4 20F71 darwin-x64, locale zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
✗ 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)
[✓] Connected device (2 available)

! Doctor found issues in 1 category.
按照提示输入了 : flutter doctor --android-licenses

报错:
flutter doctor --android-licenses
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
at com.android.repository.api.SchemaModuleSchemaModuleVersion.<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.ClassLoadersAppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 5 more

报错截图

解决方案:是缺少安卓的库造成的

Android Studio 打开 Preferences - Android SDK - SDK Tools 下选择 Android SDK Command-line Tools ,选中进行安装。如下图位置:


SDK位置

安装好之后,再到刚刚的位置选中 Android SDK Command-line Tools,Apply,之后再次在终端 flutter doctor ,会报错不一样了。这次再执行 flutter doctor --android-licenses ,会让同意一些协议,一直y,然后就成功了。成功后再次flutter doctor 就不再报错。

若报这个错误,就会造成flutter和原生混编时,flutter修改代码,原生运行不变化,必须要clean才能运行新代码。大大的影响了运行速度。

你可能感兴趣的:(flutter doctor 报错Android license status unknown. Run `flutter doctor --android-licenses` to...)