macOS flutter开发环境之cocoapods

flutter doctor运行后信息如下:

bash 复制代码
[!] Xcode - develop for iOS and macOS (Xcode 26.3)
    ✗ CocoaPods not installed.
        CocoaPods is a package manager for iOS or macOS platform code.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/to/platform-plugins
      For installation instructions, see https://guides.cocoapods.org/using/getting-started.html#installation

什么是CocoaPods

CocoaPods 管理你 Xcode 项目的库依赖。

你的项目依赖在一个称为 Podfile 的单一文本文件中指定。CocoaPods 会解决库之间的依赖,获取源代码,然后将它们链接到 Xcode 工作区中构建你的项目。

最终目标是通过创建一个更集中的生态系统,提升第三方开源库的可发现性和参与度。

安装CocoaPods

CocoaPods 是用 Ruby 构建的,可以用默认的 Ruby 安装 可在macOS上使用。不过,我们建议不要使用Ruby提供的系统 而是安装一个与系统安装分开的新版 Ruby 版本。 你可以使用像RVM或rbenv这样的Ruby版本管理器来管理多个Ruby版本,或者用Homebrew来安装一个 较新的Ruby,带有。

bash 复制代码
brew install ruby

然后根据提示我在环境变量中(~/.zshrc)增加以下配置:

bash 复制代码
export PATH="/opt/homebrew/opt/ruby/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/ruby/lib"
export CPPFLAGS="-I/opt/homebrew/opt/ruby/include"

通过执行以下命令安装CocoaPods:

bash 复制代码
gem install cocoapods

执行以后安装成功了,但是我使用flutter doctor还是提示CocoaPods not installed

这时发现执行

bash 复制代码
pod --version

发现找不到命令,那么猜测可能是环境变量的问题。在环境变量中增加

bash 复制代码
PATH=/opt/homebrew/lib/ruby/gems/4.0.0/bin:$PATH

注意这里的4.0.0是版本,这里有可能会有点区别,修改成你要版本就可以了。

重新开一个终端,发现pod命令可以找到了。运行flutter doctor 这次就正常了。

bash 复制代码
[✓] Xcode - develop for iOS and macOS (Xcode 26.3)

文档

https://guides.cocoapods.org/using/getting-started.html#installation

相关推荐
GitLqr10 小时前
Flutter + Unity 混合开发:用 unity_kit 实现高效的双向通信
flutter·unity3d·全栈
程序员老刘14 小时前
Flutter版本选择指南:3.47压哨发布,9月大限只剩一周 | 2026年8月
flutter·ai编程·客户端
xcyxiner19 小时前
flutter 运行到模拟器上
android·前端·flutter
末代iOS程序员华仔20 小时前
iOS 语聊直播/聊天APP4.3条例被拒解决
flutter·ios·swift
恋猫de小郭20 小时前
Dart 3.13 的到底改了什么?为什么很重要?有什么坑?
android·前端·flutter
Lucky092821 小时前
codex 安装前置软件
linux·运维·macos
Zguigo1 天前
lesson24-26计算机网络第三章精讲:从MAC地址到CSMA/CD,数据链路层核心知识一网打尽
计算机网络·macos
EXI-小洲2 天前
MacOS 环境下 IntelliJ IDEA 的 Maven 配置指南
macos·maven·intellij-idea
xcyxiner2 天前
flutter wsl2安装记录(使用宿主机虚拟机)
前端·flutter
Kevin Coding2 天前
JsonConvert:适用于 Android、鸿蒙与 Flutter 的 JSON 转 Model 插件
android·flutter·harmonyos