运行 flutter doctor
Flutter 提供了一个 flutter doctor 命令协助我们安装 Flutter 的依赖。它会检查本地是否有 iOS 和 Android 的开发环境。如果检测到依赖缺失,它还会给出对应依赖的安装方法
运行以下命令查看是否需要安装其它依赖项来完成安装:
flutter doctor --verbose
简写
flutter doctor --v
该命令检查您的环境并在终端窗口中显示报告
C:\Users\tong>flutter doctor -v
[√] Flutter (Channel beta, v0.5.1, on Microsoft Windows [Version 10.0.16299.125], locale zh-CN)
• Flutter version 0.5.1 at D:\Program\flutter
• Framework revision c7ea3ca377 (7 weeks ago), 2018-05-29 21:07:33 +0200
• Engine revision 1ed25ca7b7
• Dart version 2.0.0-dev.58.0.flutter-f981f09760
[!] Android toolchain - develop for Android devices (Android SDK 27.0.3)
• Android SDK at D:\Program\Android\Sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-27, build-tools 27.0.3
• ANDROID_HOME = D:\Program\Android\Sdk
• Java binary at: D:\Program\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[√] Android Studio (version 3.1)
• Android Studio at D:\Program\Android\Android Studio
• Flutter plugin version 26.0.1
• Dart plugin version 173.4700
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)
[√] Connected devices (1 available)
• MI 4LTE • 6127b114 • android-arm • Android 6.0.1 (API 23)
! Doctor found issues in 1 category.
上面有三个地方打叉 一个感叹号,iOS 那部分按照提示做就ok,最下面感叹号电脑连接上 android 手机就好 ,下面记录一下 android 那部分
✗ Android license status unknown.
下面就是记录解决问题所执行的命令
C:\Users\tong>flutter doctor --android-licenses
A newer version of the Android SDK is required. To update, run:
D:\Program\Android\Sdk\tools\bin\sdkmanager --update
C:\Users\tong>D:\Program\Android\Sdk\tools\bin\sdkmanager --update
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
at com.android.repository.api.SchemaModule$SchemaModuleVersion.
at com.android.repository.api.SchemaModule.
at com.android.sdklib.repository.AndroidSdkHandler.
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:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
... 5 more
最终找到原因是使用Java9的原因
解决方案:
使用文本编辑器打开sdkmanager.bat文件,找到DEFAULT_JVM_OPTS属性,在其最后添加‘--add-modules java.xml.bind’
(参考https://stackoverflow.com/questions/47345147/android-sdk-manager-throw-exception-with-java-9)
重新打开命令号执行flutter doctor -v,此时依旧会提示之前的错误, 接着执行flutter doctor --android-licenses
C:\Users\tong>flutter doctor --android-licenses
Warning: File C:\Users\tong\.android\repositories.cfg could not be loaded.
5 of 6 SDK package licenses not accepted. 100% Computing updates...
Review licenses that have not been accepted (y/N)? y
多输几次 y, 最后就是
---------------------------------------
Accept? (y/N): y
All SDK package licenses accepted
C:\Users\tong>flutter doctor --verbose
[√] Flutter (Channel beta, v0.5.1, on Microsoft Windows [Version 10.0.16299.125], locale zh-CN)
• Flutter version 0.5.1 at D:\Program\flutter
• Framework revision c7ea3ca377 (7 weeks ago), 2018-05-29 21:07:33 +0200
• Engine revision 1ed25ca7b7
• Dart version 2.0.0-dev.58.0.flutter-f981f09760
[√] Android toolchain - develop for Android devices (Android SDK 27.0.3)
• Android SDK at D:\Program\Android\Sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-27, build-tools 27.0.3
• ANDROID_HOME = D:\Program\Android\Sdk
• Java binary at: D:\Program\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)
• All Android licenses accepted.
[√] Android Studio (version 3.1)
• Android Studio at D:\Program\Android\Android Studio
• Flutter plugin version 26.0.1
• Dart plugin version 173.4700
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)
[√] Connected devices (1 available)
• MI 4LTE • 6127b114 • android-arm • Android 6.0.1 (API 23)
• No issues found!