下载安装
我选择的是 stable 2.8.1
SDK 的下载地址是 Downloads,mac 会自动解压文件
将 flutter 添加到 path
在使用 flutter 命令前,需要更新 pathvim ~/.zshrc
下面是 android studio / flutter / java 的配置,看下自己缺什么就补上
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
export PATH=${PATH}:/Users/wuyangjiacuo/Downloads/flutter/bin:$PATH
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home/
然后ESC
+ :wq
保存并退出
最后source ~/.zshrc
刷新下 path
flutter doctor
flutter doctor 是 flutter sdk 提供的一个检测环境的工具
在我们设置好 path 后,comman line 里面输入flutter doctor
就可以检测 flutter 运行所需的各种工具
我的输出结果是
Running "flutter pub get" in flutter_tools... 18.3s
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.8.1, on macOS 11.2.3 20D91 darwin-x64, locale
zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
✗ cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/macos#android-setup for
more details.
[!] Xcode - develop for iOS and macOS (Xcode 12.5.1)
! Flutter recommends a minimum Xcode version of 13.0.0.
Download the latest version or update via the Mac App Store.
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] VS Code (version 1.62.3)
[✓] Connected device (1 available)
! Doctor found issues in 2 categories.
可以看到我还没有安装 android 所需的工作链,xcode 的版本也偏低
因为我是安卓手机,所以就折腾安卓相关的就可以了。
abdroid 配置
android studio 下载地址
可以直接参考官方文档
已经安装了 android studio 的可以在 performance 里面的 system setting 里面查看 sdk 和 command line 是否正确安装,都正确安装后再次运行flutter doctor
就可以看到都是 ok 的了,没有 ok 的根据提示执行对应的操作就行