DEBUG.WIKI
ZgoCloud:多地区部署,按需选节点;日本、美国、香港、德国
V.PS:让项目靠近用户,亚太、欧洲、北美 KVM VPS
晚安云;香港 CN2 ¥15/月

解决 Flutter iOS 报错 CocoaPods not installed 环境检测失败修复

排查执行 flutter run 提示 Warning: CocoaPods not installed. Skipping pod install 错误,配置 Homebrew CocoaPods 路径与修复 Ruby 环境。

问题现象

在 macOS 上运行 flutter run 启动 iOS 设备时,控制台抛出警告并跳过依赖安装导致编译失败:

Warning: CocoaPods not installed. Skipping pod install.
  CocoaPods is used to retrieve the iOS and macOS platform plugin code.
  Without CocoaPods, plugins will not work on iOS or macOS.
Error: CocoaPods's specs repository is too out-of-date to satisfy dependencies.

触发根因

  1. 终端环境变量 PATH 缺少 pod 命令路径:通过 Homebrew 安装的 CocoaPods 位于 /opt/homebrew/bin(Apple Silicon)或 /usr/local/bin(Intel),该路径未被 IDE(Android Studio / VS Code)子进程继承;
  2. 系统受保护 Ruby 与用户级 gem 冲突;
  3. 缺少 Xcode Command Line Tools 授权。

解决步骤

1. 使用 flutter doctor 检查环境问题

在终端执行全面健康检查:

flutter doctor -v

查看 Xcode 模块下针对 CocoaPods 的具体报错与建议命令。

2. 使用 Homebrew 独立安装并配置 CocoaPods

避免使用系统 sudo gem install,改用隔离性更好的 Homebrew 管理:

brew install cocoapods
which pod

确认终端输出为 /opt/homebrew/bin/pod。

在 ~/.zshrc 中确认环境变量包含该路径:

export PATH="/opt/homebrew/bin:$PATH"

执行 source ~/.zshrc 生效。

3. 进入 ios 目录执行安装

进入 Flutter 项目下的 ios 子目录:

cd ios
pod install
cd ..

验证确认

重新运行 Flutter 诊断工具:

flutter doctor

输出展示 [✓] Xcode - develop for iOS and macOS (CocoaPods version 1.15.2),绿勾通过,flutter run 正常加载插件。