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

相关推荐
太子釢5 分钟前
Flutter 与 Native 混合开发策略调研与方案对比
flutter
西西学代码1 小时前
Flutter---Stack
flutter
ZZZMMM.zip6 小时前
基于鸿蒙PC与鸿蒙Flutter框架构建AI本地生活服务平台
人工智能·flutter·华为·harmonyos·鸿蒙
木叶丸6 小时前
AI 编程概念与 Harness 工程实践入门
人工智能·flutter·ios
程序员老刘1 天前
腾讯混元Hy3在Flutter项目中的实战体验
flutter·ai编程
ailinghao1 天前
flutter常用的内置特性
flutter
子非鱼94271 天前
10-Flutter调用鸿蒙原生能力前置课:MethodChannel和PlatformView准备
学习·flutter·华为·harmonyos
xd1855785551 天前
鸿蒙PC时代的AI快递查询应用:基于鸿蒙Flutter框架的跨端创新实践
人工智能·flutter·华为·harmonyos·鸿蒙
colman wang1 天前
Git指令(Mac)
git·macos
ZZZMMM.zip1 天前
基于鸿蒙PC与鸿蒙Flutter框架的AI紧急求助应用开发实践
人工智能·flutter·华为·harmonyos·鸿蒙