Android Studio如何安装Flutter(windows系统)?

Android Studio安装Flutter

  • Android Studio安装Flutter
    • 在AS中安装Flutter和Dart插件
    • 下载Flutter SDK
    • 配置环境变量
    • 运行flutter doctor
    • 配置Flutter和Dart的安装路径
    • 第一个Flutter项目

Android Studio安装Flutter

本文适用于已经有Android Studio开发基础的同学,默认已经装好Android Studio、Android SDK,jdk,git等环境。

在AS中安装Flutter和Dart插件

Android Studio如何安装Flutter(windows系统)?_第1张图片
Android Studio如何安装Flutter(windows系统)?_第2张图片

下载Flutter SDK

1、Flutter官方下载链接
2、将下载好的zip包解压到你想要安装的路径
Android Studio如何安装Flutter(windows系统)?_第3张图片

配置环境变量

1、win10如何打开环境变量界面。
首先,win+R打开运行窗口;
然后,输入sysdm.cpl命令,打开系统属性窗口;
最后,点击高级,点击环境变量按钮,打开环境变量界面。
Android Studio如何安装Flutter(windows系统)?_第4张图片
Android Studio如何安装Flutter(windows系统)?_第5张图片
2、配置系统变量
首先,新建系统变量,变量值是flutter的路径,最好复制过来。
Android Studio如何安装Flutter(windows系统)?_第6张图片Android Studio如何安装Flutter(windows系统)?_第7张图片
然后,在系统变量中找到Path,编辑Path,新建下面两行,一行一行添加,添加好之后点击确定。

%FLUTTER_HOME%\bin
%FLUTTER_HOME%\bin\cache\dart-sdk

Android Studio如何安装Flutter(windows系统)?_第8张图片
3、配置用户变量
分别新建如下两个用户变量:

PUB_HOSTED_URL
https://pub.flutter-io.cn
FLUTTER_STORAGE_BASE_URL
https://storage.flutter-io.cn

Android Studio如何安装Flutter(windows系统)?_第9张图片
Android Studio如何安装Flutter(windows系统)?_第10张图片
最后点击确定-确定,这样环境变量就配置好了。

运行flutter doctor

打开cmd,运行flutter doctor,不出意外的话,会出现如下报错。

Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
Running "flutter pub get" in flutter_tools...                      10.8s
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.3.6, on Microsoft Windows [版本 10.0.19044.2006], locale zh-CN)
[X] Android toolchain - develop for Android devices
    X Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.

[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components
[√] Android Studio (version 2021.2)
[√] Connected device (2 available)
[√] HTTP Host Availability

! Doctor found issues in 3 categories.

别着急,我们先来看第一条:

[X] Android toolchain - develop for Android devices
    X Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.

意思是无法定位Android SDK,此时只需配置ANDROID_HOME就好了。
新建用户变量,注意这里是用户变量,变量值为Android SDK的目录,最好也复制过来。
Android Studio如何安装Flutter(windows系统)?_第11张图片
Android Studio如何安装Flutter(windows系统)?_第12张图片
如果忘记了Android SDK的安装目录,可以在AS里查看。
Android Studio如何安装Flutter(windows系统)?_第13张图片
配置好之后,重启电脑,注意这里必须重启,否则不生效。

然后运行flutter doctor,发现报错发生了改变。

Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.3.6, on Microsoft Windows [版本 10.0.19044.2006], locale zh-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    X cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components
[√] Android Studio (version 2021.2)
[√] Connected device (2 available)
[√] HTTP Host Availability

! Doctor found issues in 3 categories.

发现已经能找到SDK了,但是报了新的错,首先看第一条:

 X cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.

意思是cmdline-tools没有安装,打开AS,来装一下这个插件。
Android Studio如何安装Flutter(windows系统)?_第14张图片
装好后,再运行flutter doctor,

Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.3.6, on Microsoft Windows [版本 10.0.19044.2006], locale zh-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses
[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components
[√] Android Studio (version 2021.2)
[√] Connected device (2 available)
[√] HTTP Host Availability

! Doctor found issues in 3 categories.

发现这条警告:

   ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses

我们根据它的提示,运行 flutter doctor --android-licenses,然后一路选择y直至结束。
再运行flutter doctor,

Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.3.6, on Microsoft Windows [版本 10.0.19044.2006], locale zh-CN)
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components
[√] Android Studio (version 2021.2)
[√] Connected device (2 available)
[√] HTTP Host Availability

! Doctor found issues in 2 categories.

发现前面的报错都解决了,剩下的这两条报错是由于没有装Chrome和Visual Studio的原因,不处理也可以使用。
好了,这样我们就打开AS中准备新建Flutter项目吧。

配置Flutter和Dart的安装路径

在新建Flutter项目前,我们先来配置一下Flutter和Dart的安装路径。
Android Studio如何安装Flutter(windows系统)?_第15张图片
Android Studio如何安装Flutter(windows系统)?_第16张图片
一切准备就绪,接下来就让我们开始新建第一个Flutter项目吧。

第一个Flutter项目

点击File—New—New Flutter Project。
Android Studio如何安装Flutter(windows系统)?_第17张图片
注意flutter项目的命名规范,要求单词之间以下划线连接。
构建完成后运行。
Android Studio如何安装Flutter(windows系统)?_第18张图片
Flutter就安装成功了,就请开始你的Flutter之旅吧!

你可能感兴趣的:(flutter)