欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

安装Flutter遇到的问题

程序员文章站 2022-06-01 14:11:17
...
  • 最近忽然想玩玩Flutter,安装的时候遇到了一些问题,在这里记录一下
  • 文章来自我的博客,原文链接:https://zhj.forever305.cn/2020/02/24/Flutter-Start/

1. Android license status unknown

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

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

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,然而…

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

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...

之后接受他的安装许可

安装Flutter遇到的问题

检查目前状态

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,接受所有条款

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:
---------------------------------------

重新运行自检程序

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 说明插件安装成功

安装Flutter遇到的问题

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

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已经安装完成了