快速在Windows上搭建Flutter开发环境

使用镜像

由于在国内访问Flutter有时可能会受到限制,Flutter官方为中国开发者搭建了临时镜像,大家可以将如下环境变量加入到用户环境变量中:

cmd 中设置

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

验证设置:

echo %PUB_HOSTED_URL%

以上为临时设置,如果要永久有效,用这样的步骤:
配置永久环境变量

右键桌面的此电脑->属性->高级系统设置->高级->环境变量->用户变量->新建->输入变量名和变量值->确认 无效就重启计算机

Git命令行工具安装

Flutter SDK依赖下面这些命令行工具,Flutter SDK版本管理工具使用的是git
Git for Windows (Git命令行工具)

获取Flutter SDK并安装

1.安装包获取

  • 去flutter官网下载最新可用的安装包https://flutter.dev/sdk-archive/#windows
  • 上面网址进不去,去Flutter github项目下去下载安装包 https://github.com/flutter/flutter/releases
    note:(上面两个flutter doctor提示去使用 git clone -b stable https://github.com/flutter/flutter.git )
  • 使用 git clone -b stable https://github.com/flutter/flutter.git 下载 这个也是个坑,下载速度慢,后面还报错,根据报错信息设置git config, 公司电脑也没成功git clone报错
  • 直接使用 git clone -b stable https://gitee.com/mirrors/Flutter.git直接用这个,上面有坑

2.将安装包zip解压到你想安装Flutter SDK的路径(如:C:\src\flutter;注意,不要将flutter安装到需要一些高权限的路径如C:\Program Files\)。

3.配置flutter命令环境变量

将上面的flutter\bin的全路径,添加到Path环境变量中。注意用;分割

验证flutter SDK安装的正确性并安装一下依赖包(如 dart sdk)

在cmd命令行运行

 flutter doctor

运行报错

C:\Users\stick>flutter doctor
Error: The Flutter directory is not a clone of the GitHub project.
       The flutter tool requires Git in order to operate properly;
       to set up Flutter, run the following command:
       git clone -b stable https://github.com/flutter/flutter.git

删掉之前的下载sdk,直接使用git clone -b stable https://github.com/flutter/flutter.git拉取

$ git clone -b stable https://github.com/flutter/flutter.git
Cloning into 'flutter'...
remote: Enumerating objects: 24, done.
remote: Counting objects: 100% (24/24), done.
remote: Compressing objects: 100% (16/16), done.
Receiving objects:  25% (64236/253129), 43.24 MiB | 29.00 KiB/s

error: RPC failed; curl 56 SSL read: error:00000000:lib(0):func(0):reason(0), errno 10054
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

好坑,使用下面命令关掉sslVerify

git config --global  http.sslVerify "false"

git config --global http.sslVersion tlsv1.2

//增大缓存大小(500M)
git config --global http.postBuffer 524288000

试了好多次还是报错,公司网络不行git clone报错

  • 最后直接使用gitee的镜像: git clone -b stable https://gitee.com/mirrors/Flutter.git直接用这个,上面有坑

下面是成功的显示快速在Windows上搭建Flutter开发环境_第1张图片

Android Studio安装Flutter插件

想要Android Studio直接能新建Flutter项目需要安装Flutter插件,File->Settings->Plugins->Marketplace 输入Flutter搜索安装,如果中途弹出安装失败弹框,复制弹框上的链接在浏览器上下载安装包,再使用Install Plugin From Disk(这个是Android Studio 的bug,插件安装升级时经常出现)
快速在Windows上搭建Flutter开发环境_第2张图片

总结:最快的在Window下安装Flutter 开发环境步骤

  1. 配置PUB_HOSTED_URL和FLUTTER_STORAGE_BASE_URL环境变量
  2. Git for Windows (Git命令行工具)安装;直接使用码云gitee的镜像: git clone -b stable https://gitee.com/mirrors/Flutter.git下载flutter SDK
  3. 配置flutter 命令环境变量,将上面的flutter\bin的全路径,添加到Path环境变量中
  4. 运行 flutter doctor 测试Flutter 开发环境并下载相关依赖
  5. Android Studio IDE安装Flutter插件

你可能感兴趣的:(Flutter)