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

相关推荐
1001101_QIA14 小时前
flutter打包流程
flutter
寒水馨18 小时前
macOS下载、安装PowerShell-v7.6.4(附安装包powershell-7.6.4-osx-arm64.pkg)
macos·自动化·跨平台·shell·脚本·命令行·powershell
GitLqr19 小时前
Flutter FocusNode 实战指南:玩转键盘焦点与用户输入体验
android·flutter·ios
智玲君1 天前
如何在Flutter中集成Firebase A/B Testing
flutter
末代iOS程序员华仔1 天前
OPC + Flutter + Swift:跨平台应用上架与专业知识点获客实战指南
开发语言·flutter·swift
FungLeo1 天前
Flutter/Android Release 包连不上网?AndroidManifest INTERNET 权限排查实录
android·flutter
星辰即远方2 天前
天气预报总结
macos·ios·objective-c·cocoa
xixiaoyunya2 天前
Mac远程访问新范式:基于80KM穿云箭的内网穿透技术实践
macos
秋雨梧桐叶落莳2 天前
计算器仿写总结
学习·macos·ios·objective-c·cocoa
GitLqr2 天前
深度拆解 Dart 事件循环:从面试题看清 Microtask 与 Event Queue 的执行顺序
flutter·面试·dart