使用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.SchemaModuleAppClassLoader.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 ,选中进行安装。如下图位置:
安装好之后,再到刚刚的位置选中 Android SDK Command-line Tools,Apply,之后再次在终端 flutter doctor ,会报错不一样了。这次再执行 flutter doctor --android-licenses ,会让同意一些协议,一直y,然后就成功了。成功后再次flutter doctor 就不再报错。
若报这个错误,就会造成flutter和原生混编时,flutter修改代码,原生运行不变化,必须要clean才能运行新代码。大大的影响了运行速度。