0%

安装Flutter遇到的问题

  • 最近忽然想玩玩Flutter,安装的时候遇到了一些问题,在这里记录一下

1. Android license status unknown

下载Flutter SDK,配置环境变量之后,在命令行输入flutter doctor诊断当前环境

1
2
3
4
5
6
7
8
9
10
11
12
PS C:\Users\ZHJ> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.0.0, on Microsoft Windows [Version 10.0.19564.1000], locale en-US)
[!] Android toolchain - develop for Android devices (Android SDK 29.0.2)
X Android license status unknown.
[√] Android Studio (version 3.2)
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
[!] Connected device
! No devices available

! Doctor found issues in 2 categories.

使用以下命令诊断安卓证书 flutter doctor --android-licenses

1
2
3
PS C:\Users\ZHJ> flutter doctor --android-licenses
A newer version of the Android SDK is required. To update, run:
E:\AndroidStudio\SDK\tools\bin\sdkmanager --update

按照提示,输入相应命令E:\AndroidStudio\SDK\tools\bin\sdkmanager --update,然而....

1
2
3
4
5
6
7
8
9
10
11
12
PS C:\Users\ZHJ> E:\AndroidStudio\SDK\tools\bin\sdkmanager --update
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:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 5 more

上网找了一下原因,大概是因为我的 JDK 版本太低了,需要去官网下载JDK1.8版本

重新安装之前,别忘了在控制面板里把原版JDK卸载掉

重新执行E:\AndroidStudio\SDK\tools\bin\sdkmanager --update

1
2
3
PS C:\Users\ZHJ> E:\AndroidStudio\SDK\tools\bin\sdkmanager --update
Warning: File C:\Users\ZHJ\.android\repositories.cfg could not be loaded.
License intel-android-extra-license: ] 10% Computing updates...

之后接受他的安装许可

接受许可

检查目前状态

1
2
3
4
5
6
7
8
9
10
11
12
PS C:\Users\ZHJ> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.0.0, on Microsoft Windows [Version 10.0.19564.1000], locale en-US)
[!] Android toolchain - develop for Android devices (Android SDK 29.0.2)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[√] Android Studio (version 3.2)
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
[!] Connected device
! No devices available

! Doctor found issues in 2 categories.

系统提示有一些证书还未被接受,按照提示重新执行flutter doctor --android-licenses,接受所有条款

1
2
3
4
5
6
7
PS C:\Users\ZHJ> flutter doctor --android-licenses
Warning: File C:\Users\ZHJ\.android\repositories.cfg could not be loaded.[========= ] 25% F[========= ] 25% Fetch remote repository...
5 of 7 SDK package licenses not accepted. 100% Computing updates...
Review licenses that have not been accepted (y/N)? y

1/5: License android-googletv-license:
---------------------------------------

重新运行自检程序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
PS C:\Users\ZHJ> flutter doctor -v
[√] Flutter (Channel stable, v1.0.0, on Microsoft Windows [Version 10.0.19564.1000], locale en-US)
• Flutter version 1.0.0 at E:\Flutter\flutter
• Framework revision 5391447fae (1 year, 3 months ago), 2018-11-29 19:41:26 -0800
• Engine revision 7375a0f414
• Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[√] Android toolchain - develop for Android devices (Android SDK 29.0.2)
• Android SDK at E:\AndroidStudio\SDK
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• ANDROID_HOME = E:\AndroidStudio\SDK
• Java binary at: E:\AndroidStudio\install\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
• All Android licenses accepted.

[√] Android Studio (version 3.2)
• Android Studio at E:\AndroidStudio\install
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[!] Connected device
! No devices available

! Doctor found issues in 1 category.

可以看到,Android toolchain 问题已经解决了

2. Android Studio Flutter plugin not installed

至于这个问题,直接在 Android Stuio 插件安装界面安装flutter插件即可

flutter插件安装

安装完成后,重启 Android Studio

如果再启动界面看到 Start a new Flutter project 说明插件安装成功

插件安装成功

运行自检程序查看环境状态

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
PS C:\Users\ZHJ> flutter doctor -v
[√] Flutter (Channel stable, v1.0.0, on Microsoft Windows [Version 10.0.19564.1000], locale en-US)
• Flutter version 1.0.0 at E:\Flutter\flutter
• Framework revision 5391447fae (1 year, 3 months ago), 2018-11-29 19:41:26 -0800
• Engine revision 7375a0f414
• Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[√] Android toolchain - develop for Android devices (Android SDK 29.0.2)
• Android SDK at E:\AndroidStudio\SDK
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• ANDROID_HOME = E:\AndroidStudio\SDK
• Java binary at: E:\AndroidStudio\install\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
• All Android licenses accepted.

[√] Android Studio (version 3.2)
• Android Studio at E:\AndroidStudio\install
• Flutter plugin version 31.3.1
• Dart plugin version 181.5656
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[!] Connected device
! No devices available

! Doctor found issues in 1 category.

OK,现在flutter已经安装完成了

谢谢你请我喝快乐水 😜

欢迎关注我的其它发布渠道