1. 安装和环境配置
大约 3 分钟
参考:https://flutter.cn/docs/get-started/install/macos
环境确认
本地环境:
macOS Catalina: 10.15.7
安装配置
1. 获取安装包
我选择从git上获取
# 目录自己定。
cd ~/dev
git clone https://github.com/flutter/flutter.git -b stable
2. 配置环境变量
# 这个依赖本地生效环境变量文件
vim ~/.bashrc
# 添加如下内容
# FLUTTER
export PATH=$PATH:~/dev/flutter/bin
source ~/.bashrc
3. 验证安装
通过运行以下命令来查看当前环境是否需要安装其他的依赖(如果想查看更详细的输出,增加一个 -v 参数即可):
flutter doctor
这个命令会检查你当前的配置环境,并在命令行窗口中生成一份报告。安装 Flutter 会附带安装 Dart SDK,所以不需要再对 Dart 进行单独安装。你需要仔细阅读上述命令生成的报告,看看别漏了一些需要安装的依赖,或者需要之后执行的命令(这个会以 加粗的文本 显示出来)。
输入内容:
flutter doctor
Downloading Darwin x64 Dart SDK from Flutter engine 54a7145303f0dd9d0f93424a2e124eb4abef5091...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 208M 100 208M 0 0 537k 0 0:06:37 0:06:37 --:--:-- 475k
Building flutter tool...
Resolving dependencies... (2:14.1s)
Got dependencies.
Downloading Material fonts... 5.5s
Downloading Gradle Wrapper... 1,281ms
Downloading package sky_engine... 4.0s
Downloading flutter_patched_sdk tools... 8.5s
Downloading flutter_patched_sdk_product tools... 8.8s
Downloading darwin-x64 tools... 76.5s
Downloading libimobiledevice... 1,759ms
Downloading usbmuxd... 1,591ms
Downloading libplist... 1,445ms
Downloading openssl... 3.9s
Downloading ios-deploy... 1,850ms
Downloading darwin-x64/font-subset tools... 4.8s
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.16.4, on Mac OS X 10.15.7 19H2026 darwin-x64, locale zh-Hans-CN)
[✗] Android toolchain - develop for Android devices
✗ 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/macos#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.
[✗] Xcode - develop for iOS and macOS
✗ Xcode installation is incomplete; a full installation is necessary for iOS and macOS development.
Download at: https://developer.apple.com/xcode/
Or install Xcode via the App Store.
Once installed, run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch
✗ CocoaPods not installed.
CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your
plugin usage on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google
Chrome.app/Contents/MacOS/Google Chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[!] Android Studio (not installed)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.1)
[✓] VS Code (version 1.85.0)
[!] Proxy Configuration
! NO_PROXY is not set
[✓] Connected device (1 available)
[✓] Network resources
! Doctor found issues in 5 categories.
针对以上问题来分别解决。 3个严重问题
- 没有安卓SDK
- 没有Xcode
- 没有Chrome内核
2个警告问题
- 没有Android Studio
- 没有配置Proxy
禁用匿名分析
flutter config --no-analytics
4. 平台配置
设置iOS开发环境
设置Android开发环境
下载地址: https://developer.android.google.cn/studio?hl=zh-cn 安装软件
针对以下情况,信任安卓SDK证书
✗ 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.
flutter doctor --android-licenses
5. 配置IDE
vscode搜索flutter
并安装该插件
6. 创建第一个项目
遇到的问题
安装Xcode:12.3版本之后,发现flutter无法连接上iOS模拟器。因此 重新回退flutter版本至3.10.7
git reset --hard e285328
然后重新执行 flutter doctor
, 等下载完成,查看结果