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

React Native项目Jenkins执行Xcodebuild Archive失败求助

问题描述

本地执行以下命令可正常生成React Native项目的iOS归档包,但在Jenkins中执行相同命令时失败:

xcrun xcodebuild archive -workspace AppName.xcworkspace -scheme Test -sdk iphoneos -configuration release -allowProvisioningUpdates -destination "generic/platform=iOS" arch=x86_64  -archivePath "/Users/ali/Desktop/Test_bulds"

Jenkins执行时的报错信息:

/Users/ali/jenkins/workspace/Mobile/MobileAppBuild/ios/Pods/Pods.xcodeproj: 警告:iOS部署目标“IPHONEOS_DEPLOYMENT_TARGET”设置为8.0,但支持的部署目标版本范围是9.0到15.2.99。(来自项目“Pods”的目标“react-native-blur”)
** 归档失败 **

以下构建命令执行失败:
    PhaseScriptExecution [CP] 嵌入Pods框架 /Users/ali/Library/Developer/Xcode/DerivedData/Appname-hamnkyelypjutaefdzwfxmvlwith/Build/Intermediates.noindex/ArchiveIntermediates/Test/IntermediateBuildFilesPath/Appname.build/Release-iphoneos/Appname.build/Script-CF1348D5D60844C3DD63C481.sh(来自项目“AppNAme”的目标“AppName”)
解决方案

1. 统一Pod的iOS部署目标

警告显示react-native-blur的部署目标为8.0,超出当前Xcode支持的版本范围,这是导致后续脚本执行失败的根源之一。在iOS目录的Podfile末尾添加以下代码,强制所有Pod使用与项目一致的部署目标(建议设为9.0或更高):

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'
    end
  end
end

在Jenkins构建步骤中,先执行cd ios && pod install --repo-update,确保Pod配置更新生效。

2. 修复Jenkins执行环境的权限问题

脚本执行失败大概率是权限不足导致的:

  • 确保Jenkins运行用户(ali)对DerivedData目录和Jenkins工作区拥有读写权限,执行命令:
    chown -R ali:staff /Users/ali/Library/Developer/Xcode/DerivedData /Users/ali/jenkins/workspace/Mobile/MobileAppBuild
    
  • 构建前添加清理缓存步骤:rm -rf ~/Library/Developer/Xcode/DerivedData,避免旧缓存干扰。

3. 修正构建命令的架构参数

你指定的arch=x86_64是模拟器架构,iOS真机归档应使用默认的真机架构,移除该参数后命令如下:

xcrun xcodebuild archive -workspace AppName.xcworkspace -scheme Test -sdk iphoneos -configuration release -allowProvisioningUpdates -destination "generic/platform=iOS" -archivePath "/Users/ali/Desktop/Test_bulds"

4. 对齐Jenkins与本地的Xcode环境

确保Jenkins使用的Xcode版本和路径与本地一致:

  • 在本地执行xcode-select -p获取当前Xcode路径,比如/Applications/Xcode.app/Contents/Developer
  • 在Jenkins构建步骤开头添加命令:xcode-select -switch /Applications/Xcode.app/Contents/Developer(替换为你的实际路径),或者在Jenkins全局工具配置中设置正确的Xcode路径。

内容的提问来源于stack exchange,提问作者DropAndTrap

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 18:55:23