You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio运行Flutter iOS项目提示CocoaPods未安装报错

问题现象
  • 在Android Studio中运行Flutter应用至iPhone 12 Pro Max模拟器时,抛出CocoaPods未安装、跳过pod install的错误,应用调试启动失败
  • 终端直接执行flutter run命令可正常启动、运行应用
  • 执行flutter doctor -v做全链路环境校验无报错,检测结果显示CocoaPods 1.11.3已正常安装,所有开发环境配置项均校验通过
运行报错日志
Launching lib/main.dart on iPhone 12 Pro Max in debug mode...
Warning: CocoaPods not installed. Skipping pod install.
  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, refer to official Flutter platform plugin documentation.
Refer to official CocoaPods getting started guide for installation instructions.

CocoaPods not installed or not in valid state.
Error launching application on iPhone 12 Pro Max.
环境检测结果

flutter doctor -v执行输出如下:

flutter doctor -v
[✓] Flutter (Channel stable, 3.0.4, on macOS 12.4 21F79 darwin-arm, locale en-GB)
    • Flutter version 3.0.4 at /opt/homebrew/Caskroom/flutter/2.5.0/flutter
    • Upstream repository configured correctly
    • Framework revision 85684f9300 (2 weeks ago), 2022-06-30 13:22:47 -0700
    • Engine revision 6ba2af10bb
    • Dart version 2.17.5
    • DevTools version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/elamparithibalakrishnan/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin installed
    • Dart plugin installed
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[✓] Connected device (3 available)
    • iPhone 12 Pro Max (mobile) • 0C7D4F63-17B1-4E66-8277-767ED0672937 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-5
      (simulator)
    • macOS (desktop)            • macos                                • darwin-arm64   • macOS 12.4 21F79 darwin-arm
    • Chrome (web)               • chrome                               • web-javascript • Google Chrome 103.0.5060.114
    ! Error: iPhone is not connected. Xcode will continue when iPhone is connected. (code -13)

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
问题根因

该问题是macOS图形化应用启动时默认不加载Shell配置文件的PATH环境变量导致:

  • 终端启动时会自动加载~/.zshrc/~/.bash_profile中配置的Homebrew二进制路径,因此可以正常识别通过Homebrew安装的CocoaPods,flutter run和flutter doctor命令均可正常执行
  • 从Dock栏、启动台直接点开Android Studio时,进程不会继承Shell的PATH配置,无法找到M1芯片Mac默认安装在/opt/homebrew/bin路径下的pod可执行文件,因此误判CocoaPods未安装
解决方案
  • 方案一:通过终端启动Android Studio
    完全退出已打开的Android Studio,在终端执行open /Applications/Android\ Studio.app启动IDE。该启动方式下IDE进程会继承终端的PATH配置,可直接识别到CocoaPods,无额外配置成本。
  • 方案二:创建pod命令全局软链接
    终端执行sudo ln -s $(which pod) /usr/local/bin/pod,输入当前系统用户的开机密码完成软链接创建,重启Android Studio后即可全局识别到CocoaPods,长期有效。
  • 方案三:手动配置Android Studio环境变量
    打开Android Studio的启动环境配置页,在PATH变量中追加Homebrew二进制路径:M1芯片Mac追加/opt/homebrew/bin,Intel芯片Mac追加/usr/local/bin,保存配置后重启Android Studio生效。

内容的提问来源于stack exchange,提问作者Elam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 15:21:17