遇到的问题集合
- 工具链缺失
- 缺失 Simulator
- 缺失签名
- 缺失运行依赖
不是每一个是必须解决的,先梳理输出常规步骤,不同问题解决在最后
🧭 macOS 配置 Flutter 全流程指南(含 Xcode 权限与证书排查)
🧱 一、基本环境搭建
✅ 1. 安装 Flutter SDK
可选择以下任一方式:
- 官网下载并解压:docs.flutter.dev/get-started...
- 或使用命令行安装(推荐):
手动档:
- 下载 Flutter SDK
下载官方压缩包并解压:
shell
unzip flutter_macos_3.xx.x-stable.zip -d ~/
-
配置环境变量
编辑 Shell 配置文件(如
~/.zshrc
):shellecho 'export PATH="$PATH:$HOME/flutter/bin"' >> ~/.zshrc echo 'export PUB_HOSTED_URL=https://pub.flutter-io.cn' >> ~/.zshrc echo 'export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn' >> ~/.zshrc source ~/.zshrc # 立即生效
-
验证安装
bashflutter --version # 检查版本 flutter doctor -v # 检查依赖并安装缺失项(如 Xcode、Android SDK)
自动挡:
-
安装 Homebrew(若未安装)
bash/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
-
通过 Homebrew 安装 Flutter
bashbrew install --cask flutter # 安装稳定版
-
配置镜像环境变量
编辑
~/.zshrc
:bashecho 'export PUB_HOSTED_URL=https://pub.flutter-io.cn' >> ~/.zshrc echo 'export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn' >> ~/.zshrc source ~/.zshrc
-
验证安装
bashwhich flutter # 检查路径(应为 /usr/local/bin/flutter) flutter --version # 确认版本 flutter doctor # 修复依赖问题
✅ 2. 安装依赖工具链
css
brew install --cask flutter
brew install --cask android-studio
brew install cocoapods
🧰 二、配置 Xcode 环境
📦 1. 安装 Xcode 并完成初始化
- 从 App Store 安装 Xcode;建议最新版本(需要注册登陆 apple 账号)
- 打开一次 Xcode 接受协议
- 执行命令安装开发工具包:
csharp
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch
🔑 2. 虚拟机缺失
如果你遇到类似错误:

❌
"Unable to get list of installed Simulator runtimes"
于 Xcode 的问题:"Unable to get list of installed Simulator runtimes",这通常是由于 Xcode 缺少签名配置、权限问题或设备模拟器未正确初始化导致。
执行以下命令查看已安装模拟器:
xcrun simctl list
若为空或出错,可通过以下方式恢复:
- 确保你没有禁用 Xcode 的模拟器支持(部分精简安装可能不含 macOS runtime);
- 手动安装模拟器:
perl
open -a "Simulator"
# 或在 Xcode > Settings > Platforms > + 添加 iOS/macOS 模拟器

如果只运行 macos 此时已经够了

🧪 3. 签名(不打算上架先不管)
异常报错其实是因为没在 macos 路径执行 pod install

- 打开项目
macos/Runner.xcodeproj
; - 点击左侧
Runner
→ 选择Signing & Capabilities
; - 勾选 ✅
Automatically manage signing
; - 设置一个有效的
Team
(需登录 Apple ID); - 检查
Provisioning Profile
是否为Development
类型。
确保 Xcode 配置了 正确的签名证书 和 开发团队,这是必须的:
- 打开 Xcode 项目:
macos/Runner.xcodeproj
。 - 选择 Runner → Signing & Capabilities。

- 选择 Automatically manage signing。
- 确保选择了一个有效的 Team ,并且 Xcode 使用 合适的开发证书。

📦 三、CocoaPods 环境配置
Flutter 在构建 macOS 或 iOS 应用时依赖 CocoaPods 管理原生依赖。
🧩 安装/修复 CocoaPods
arduino
sudo gem install cocoapods
pod setup
如果遇到 pod install
卡住或失败问题:
bash
cd macos
pod deintegrate
pod install
🔍 四、运行环境诊断(flutter doctor)
执行 flutter doctor -v
可全面检查环境配置:
flutter doctor -v
重点检查以下项是否都为 ✅:
- Flutter
- Xcode
- CocoaPods
- Connected device(确认能检测 macOS 或 iOS 模拟器)
🛠 五、常见错误与解决
错误信息或问题 | 原因 | 解决建议 |
---|---|---|
Unable to get list of installed Simulator runtimes |
模拟器未安装 / Xcode未初始化 | 运行 xcodebuild -runFirstLaunch 或手动安装模拟器 |
Signing for "Runner" requires a development team |
没有设置有效签名 | Xcode 中设置 Team 为开发者账号 |
Pod install failed |
CocoaPods 未初始化或版本冲突 | 执行 pod deintegrate + pod install |
command line tools not set |
没有设置 xcode-select 路径 | sudo xcode-select --switch /Applications/Xcode.app/... |
xcrun: error: unable to find utility "simctl" |
命令行工具未激活或 Xcode 错误 | 重新安装 Xcode 或重启后执行 xcode-select --install |
运行成功
