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

Flutter项目中手动添加指定iOS Pod依赖的正确位置咨询

Flutter项目中手动添加指定iOS Pod依赖的正确位置咨询

嗨,这个问题我之前帮好几个开发者捋清楚过,直接给你说最靠谱的方案~

你完全不用纠结,正确的做法是把这两个Pod依赖添加到Runner target的代码块内部,也就是你提到的第二种方式。绝对不能把它们放在post_install代码块的后面,那样Pod根本识别不到这些依赖,肯定会安装失败。

给你整理好的标准Podfile片段参考:

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  # 把你的第三方Pod依赖加在这里就行
  pod 'GMGdtAdapter-Beta', '4.15.40.1'
  pod 'GMKsAdapter-Beta', '3.3.76.1'

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))

  target 'RunnerTests' do
    inherit! :search_paths
  end
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
  end
end

为啥第一种方式不行?因为post_install是Pod安装完成后才会执行的钩子脚本,它的作用是修改已安装Pods的构建配置,根本不是用来声明新依赖的地方。把依赖写在那里,Pod完全不会去解析和拉取这些库。

最后提醒一句:添加完依赖后,要么进入iOS目录执行pod install,要么直接在Flutter项目根目录跑flutter pub get(它会自动触发iOS端的Pod安装流程),确保这些依赖被正确拉取到项目里。

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.08 09:49:38