M1芯片Mac上Xcode测试包加载失败:x86_64与arm64架构不兼容
M1设备Xcode测试包架构不兼容问题解决方案
方案1:拆分主目标与测试目标的架构配置
你的核心矛盾是主项目因依赖Pods必须排除arm64才能构建,但测试bundle需要适配M1模拟器的arm64架构。可以通过单独配置两类目标的架构解决:
- 打开项目Build Settings,找到
Excluded Architectures选项 - 点击右侧
+号,选择Add Configuration Setting - 选中主目标,将其
Excluded Architectures(Debug/Release)设为arm64 - 选中测试目标,清空其
Excluded Architectures中的内容,不排除任何架构 - 修改
Podfile,添加post_install脚本,让Pods针对主/测试目标分别应用架构规则:
post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| # 给主目标关联的Pods排除arm64模拟器架构 if target.name.match?(/^你的主目标名称|主目标依赖的Pods标识/) config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64' # 测试目标关联的Pods不排除arm64 elsif target.name.match?(/^你的测试目标名称|测试目标依赖的Pods标识/) config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = '' end end end end
- 执行
pod install后重新构建项目
方案2:强制测试目标以Rosetta模式运行
如果方案1无法适配部分特殊Pods,可以让模拟器以Rosetta模式运行,兼容x86_64架构的测试包:
- 点击Xcode顶部菜单栏
Product > Destination > Destination Architectures,勾选Show Rosetta Destinations - 在设备选择列表中,选择带有
(Rosetta)后缀的模拟器 - 重新构建并运行测试
验证要点
- 构建后查看测试目标的链接器命令:方案1下应为
arm64-apple-ios11.0-simulator,方案2下保持x86_64-apple-ios11.0-simulator即可 - 确保主目标和测试目标的
Build Active Architecture Only均设为No
内容的提问来源于stack exchange,提问作者Frankie Simon
相关产品推荐
相关产品推荐

