GitLab CI/CD iOS构建失败:CocoaPods已安装但状态异常
问题重现
Android构建环节正常,但iOS构建触发以下错误:
Warning: CocoaPods is installed but broken. Skipping pod install. You appear to have CocoaPods installed but it is not working. This can happen if the version of Ruby that CocoaPods was installed with is different from the one being used to invoke it. This can usually be fixed by re-installing CocoaPods. To re-install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions. CocoaPods not installed or not in valid state. Cleaning up project directory and file based variables 00:00 ERROR: Job failed: exit status 1
当前.gitlab-ci.yml配置如下:
stages: - build build_project: stage: build only: - 75-setup-ci-cd-pipeline script: - flutter clean - flutter build ipa --flavor production -t lib/main_production.dart - flutter build appbundle --flavor production -t lib/main_production.dart tags: - flutter
解决方案
问题核心是CI环境中CocoaPods的Ruby依赖版本不匹配,需在构建脚本中添加CocoaPods修复步骤。修改后的.gitlab-ci.yml脚本部分如下:
script: - flutter clean # 修复CocoaPods依赖 - gem install cocoapods - cd ios - pod deintegrate - pod install - cd .. # 执行构建命令 - flutter build ipa --flavor production -t lib/main_production.dart - flutter build appbundle --flavor production -t lib/main_production.dart
步骤说明
gem install cocoapods:基于当前CI环境的Ruby版本重新安装CocoaPods,解决版本不匹配问题pod deintegrate:彻底清理iOS项目中旧的Pod配置和依赖,避免残留冲突pod install:重新生成适配当前环境的Pod依赖配置
如果项目需要指定特定版本的CocoaPods,可将安装命令改为gem install cocoapods --version 1.12.1(替换为项目兼容的版本号)。
内容的提问来源于stack exchange,提问作者jitendra purohit

