MAC上Flutter环境搭建记录
官网
配置国内镜像
-
配置命令
export PUB_HOSTED_URL=pub.flutter-io.cn export FLUTTER_STORAGE_BASE_URL=storage.flutter-io.cn
下载安装Flutter
- 下载Flutter SDK,解压配置即可;
- 通过 git 方式获取(推荐此方式):
"git clone https://github.com/flutter/flutter.git -b stable"
- 遇到问题:SSL_ERROR_SYSCALL in connection to github.com:443
一般为网络问题或者代理问题
fatal: unable to access 'https://github.com/flutter/flutter.git/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
-
解决方案:分为http和https
git config --global --unset http.proxy git config --global --unset https.proxy
设置完以后重启终端!
将 Flutter 添加全局环境变量
- 打开(或创建)
.bash_profile
. 我在 本用户名 文件夹下创建
参考flutter中文网教程:打开(或创建) $HOME/.bash_profile
. 文件路径和文件名可能在您的机器上不同.
先 open .bash_profile
查看是否有.bash_profile 文件,如无 touch .bash_profile
添加如下配置
export PUB_HOSTED_URL=https://pub.flutter-io.cn //国内用户需要设置
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn //国内用户需要设置
export PATH=PATH_TO_FLUTTER_GIT_DIRECTORY/flutter/bin:$PATH
-
注意:
PATH_TO_FLUTTER_GIT_DIRECTORY
为你flutter的路径,比如“~/document/code”#我的配置如下 export PATH=/Users/用户名文件夹/flutter/bin:$PATH
-
随后,通过
which flutter
验证已配置的 Flutter 是否可用:which flutter
通过 flutter doctor 验证当前 Flutter 开发环境是否完善
flutter doctor
-
遇到问题:Failed to retrieve the Dart SDK
Downloading Dart SDK from Flutter engine 241c87ad800beeab545ab867354d4683d5bfb6ce... % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- 0:03:02 --:--:-- 0 curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to storage.googleapis.com:443
Failed to retrieve the Dart SDK from: storage.googleapis.com/flutter_inf… If you're located in China, please see this page: flutter.dev/community/c…
解决办法:切换了下VPN的服务器节点,就好了。猜测是网络不好!
重新运行之后正常:如图
环境搭建完成,还差 Android Studio 需要安装和配置。
转载自:https://juejin.cn/post/6990173694374969352