flutter 配置开发环境

获取 Flutter SDK

1
2
//beta 版本
git clone -b beta https://github.com/flutter/flutter.git

添加系统变量

1
2
3
4
5
6
7
8
9
10
//添加临时系统变量 `pwd` 替换为刚才克隆的 flutter 的路径
export PATH=`pwd`/bin:$PATH
// 为保证在任意位置可执行 flutter 命令,应该添加永久系统变量
vi $HOME/.bash_profile
//添加以下内容 [PATH_TO_FLUTTER_GIT_DIRECTORY] 替换为刚才克隆的 flutter 的路径
export PATH=[PATH_TO_FLUTTER_GIT_DIRECTORY]/flutter/bin:$PATH
//更新系统变量
source $HOME/.bash_profile
//可查看是否添加成功
echo $PATH

安装依赖

1
flutter doctor
1
2
3
4
Downloading Dart SDK from Flutter engine 13cf22c284c24f81357aec6a89074a536efbf4d1...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:01:14 --:--:-- 0

此步骤需要终端翻墙,否则可能会报错:
curl: (7) Failed to connect to storage.googleapis.com port 443: Operation timed out

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//过程较慢,耐心等待
╔════════════════════════════════════════════════════════════════════════════╗
║ Welcome to Flutter! - https://flutter.io ║
║ ║
║ The Flutter tool anonymously reports feature usage statistics and crash ║
║ reports to Google in order to help Google contribute improvements to ║
║ Flutter over time. ║
║ ║
║ Read about data we send with crash reports: ║
║ https://github.com/flutter/flutter/wiki/Flutter-CLI-crash-reporting ║
║ ║
║ See Google's privacy policy: ║
║ https://www.google.com/intl/en/policies/privacy/ ║
║ ║
║ Use "flutter config --no-analytics" to disable analytics and crash ║
║ reporting. ║
╚════════════════════════════════════════════════════════════════════════════╝
Downloading Material fonts... 7.5s
Downloading package sky_engine... 6.3s
Downloading common tools... 14.9s
Downloading darwin-x64 tools... 32.1s
...