M1芯片Jenkins运行Xcode测试遇架构不兼容问题求解决方案
解决M1芯片Jenkins上Xcode单元测试架构不兼容问题
针对你遇到的「本地开Rosetta测试正常,Jenkins上报mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')」问题,给你几个实用的解决方向:
让Jenkins以Rosetta模式运行
找到Jenkins应用(如果是brew安装的,一般在/Applications/Jenkins.app),右键点「显示简介」,勾选「使用Rosetta打开」,然后重启Jenkins服务。如果是命令行启动的Jenkins,停止服务后用arch -x86_64 jenkins start命令启动,强制以x86_64架构运行Jenkins进程。调整Xcode项目的架构配置
打开Xcode项目,进入测试Target的「Build Settings」:- 把「Architectures」设为
Standard Architectures (arm64, x86_64),确保同时支持两种架构 - 「Build Active Architecture Only」在Debug模式设为Yes,Release模式设为No,保证构建时生成通用二进制
- 检查「Excluded Architectures」,确认没有排除arm64(别漏了测试Target的配置)
- 把「Architectures」设为
在Jenkins构建脚本里指定架构参数
用xcodebuild命令跑测试时,显式指定架构,比如:xcodebuild test -workspace YourApp.xcworkspace -scheme YourTestScheme -destination 'platform=iOS Simulator,name=iPhone 14' -arch arm64 -arch x86_64如果是MacOS测试,把destination换成对应Mac设备,架构参数保持一致。
检查第三方依赖的架构兼容性
用lipo -info YourThirdParty.framework/YourThirdParty命令查看依赖库支持的架构,如果缺少arm64,要么更新依赖到支持arm64的版本,要么自己重新编译依赖为通用架构(同时包含x86_64和arm64)。
内容的提问来源于stack exchange,提问作者Daniele Calvagno
相关产品推荐
相关产品推荐

