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

Posted 谭老鸭

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android Studio如何安装Flutter(windows系统)?相关的知识,希望对你有一定的参考价值。

android Studio安装Flutter

Android Studio安装Flutter

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

在AS中安装Flutter和Dart插件


下载Flutter SDK

1、Flutter官方下载链接
2、将下载好的zip包解压到你想要安装的路径

配置环境变量

1、win10如何打开环境变量界面。
首先,win+R打开运行窗口;
然后,输入sysdm.cpl命令,打开系统属性窗口;
最后,点击高级,点击环境变量按钮,打开环境变量界面。


2、配置系统变量
首先,新建系统变量,变量值是flutter的路径,最好复制过来。

然后,在系统变量中找到Path,编辑Path,新建下面两行,一行一行添加,添加好之后点击确定。

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


3、配置用户变量
分别新建如下两个用户变量:

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



最后点击确定-确定,这样环境变量就配置好了。

运行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 SDK的安装目录,可以在AS里查看。

配置好之后,重启电脑,注意这里必须重启,否则不生效。

然后运行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,来装一下这个插件。

装好后,再运行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的安装路径。


一切准备就绪,接下来就让我们开始新建第一个Flutter项目吧。

第一个Flutter项目

点击File—New—New Flutter Project。

注意flutter项目的命名规范,要求单词之间以下划线连接。
构建完成后运行。

Flutter就安装成功了,就请开始你的Flutter之旅吧!

Android Studio Dart 和 Flutter 插件未安装

【中文标题】Android Studio Dart 和 Flutter 插件未安装【英文标题】:Android Studio Dart And Flutter Plugin is not installed 【发布时间】:2021-01-29 20:14:20 【问题描述】:

这是flutter doctor 结果:

[√] Flutter (Channel stable, 1.22.1, on Microsoft Windows [Version 10.0.18362.30], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[!] Android Studio
    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 插件。但问题仍然存在。我该如何解决这个问题?

【问题讨论】:

有关颤振问题的相关错误报告:github.com/flutter/flutter/issues/37670 【参考方案1】:

只需在您的终端上运行它(Mac 用户)

ln -s ~/Library/Application\ Support/Google/AndroidStudio4.1/plugins ~/Library/Application\ Support/AndroidStudio4.1

【讨论】:

这里是明智的解决方案! 在互联网上关于这个问题的许多建议中,这是唯一对我有用的东西。 感谢您拯救了我的一天,感谢您为 Android Studio 4.2 ln -s ~/Library/Application\ Support/Google/AndroidStudio4.2/plugins ~/Library/Application\ Support/AndroidStudio4.2跨度> 【参考方案2】:

大家好

我建议大家按照 Flutter 文档网站告诉您的步骤进行操作

windows用户-->有些人被flutter医生检测到了flutter和dart插件,没有的人很少

我在尝试安装时遇到了这个问题... 我做了所有事情,比如安装了颤振和飞镖插件,但我的颤振医生还没有检测到插件......

以下步骤对我有用

flutter channel dev
flutter upgrade
flutter config --android-studio-dir="C:\Program Files\Android\Android Studio"
flutter doctor -v

注意:--- flutter config --android-studio-dir="C:\Program Files\Android\Android Studio" 应该是示例 flutter config "C:\Program Files\Android\Android Studio"

以上步骤对我有用,我希望它也能帮助你:)

【讨论】:

【参考方案3】:

将频道主更改为开发。 然后升级。

flutter channel dev
flutter channel upgrade

再试一次

flutter doctor

注意:我认为这是 Android Studio 4.1 的问题...

【讨论】:

【参考方案4】:

既然你说你在 Android Studio 中安装了 Flutter 插件,并且如果 Android Studio 正确显示了你安装的插件,那么没有理由相信任何第三方工具会报告其他情况。

此外,这不会影响您的 Flutter 开发,您的 IDE 插件将在 IDE 中按预期工作,并且 Flutter 工具的命令独立于所使用的 IDE 工作。

Android Studio 4.1 显然是changed its default plugin install path。

相关github问题:[flutter_tools] IDE plugin validators should be deprecated #61246

Flutter 不直接使用 IDE 插件,因此医生未能检测到它们不会影响任何行为(这很烦人)。

【讨论】:

【参考方案5】:
    打开终端: run> 颤振通道开发 run>flutter 频道升级

【讨论】:

【参考方案6】:

打开终端: Mac 用户: 颤振配置 --android-studio-dir=/Applications/Android\ Studio.app

【讨论】:

这在flutter找不到Android Studio时很有用。【参考方案7】:

从 Android Studio 重新安装 Flutter 插件

【讨论】:

【参考方案8】:

您使用的是 Android Studio V 4.1 吗? Android Studio V4.1 有一个问题。 尝试重新安装 Android Studio 但版本 4.0.1 并重试,这可能会解决您的问题。

【讨论】:

【参考方案9】:
    打开 Android 工作室 按照路径 配置 > 插件 > 市场 > 搜索 Flutter & Dart > 安装 重启IDE(Android studio) 打开终端并导出 Flutter 路径 并运行 flutter doctor -v

【讨论】:

【参考方案10】:

如果您要升级现有项目:

运行

git clone https://github.com/flutter/flutter.git

在您的终端中。

一定要删除你App根目录下的Flutter文件夹。否则你会弹出超过 50k 的错误

【讨论】:

【参考方案11】:

检查你的颤振路径

which flutter

如果你得到/path-to-flutter-sdk/bin//flutter 或类似的,你可能在你的$HOME/.rc_file 中添加了一个额外的/。去掉最后一个'/',重启终端再试一次

【讨论】:

【参考方案12】:

这对我有用

flutter channel dev

flutter doctor

【讨论】:

以上是关于Android Studio如何安装Flutter(windows系统)?的主要内容,如果未能解决你的问题,请参考以下文章

如何在android studio中配置flutter项目?

如何在 Android Studio 中打开现有的 Flutter 项目

如何在 Android Studio 中为 Flutter 应用程序打开 iOS 模拟器

安装android studio&flutter

Flutter 没有为 Android Studio 正确安装

Flutter Doctor(不正确?)报告未安装 Android Studio Flutter 插件