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

M1芯片Mac上Xcode测试包加载失败:x86_64与arm64架构不兼容

M1设备Xcode测试包架构不兼容问题解决方案

方案1:拆分主目标与测试目标的架构配置

你的核心矛盾是主项目因依赖Pods必须排除arm64才能构建,但测试bundle需要适配M1模拟器的arm64架构。可以通过单独配置两类目标的架构解决:

  1. 打开项目Build Settings,找到Excluded Architectures选项
  2. 点击右侧+号,选择Add Configuration Setting
  3. 选中主目标,将其Excluded Architectures(Debug/Release)设为arm64
  4. 选中测试目标,清空其Excluded Architectures中的内容,不排除任何架构
  5. 修改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
  1. 执行pod install后重新构建项目

方案2:强制测试目标以Rosetta模式运行

如果方案1无法适配部分特殊Pods,可以让模拟器以Rosetta模式运行,兼容x86_64架构的测试包:

  1. 点击Xcode顶部菜单栏Product > Destination > Destination Architectures,勾选Show Rosetta Destinations
  2. 在设备选择列表中,选择带有(Rosetta)后缀的模拟器
  3. 重新构建并运行测试

验证要点

  • 构建后查看测试目标的链接器命令:方案1下应为arm64-apple-ios11.0-simulator,方案2下保持x86_64-apple-ios11.0-simulator即可
  • 确保主目标和测试目标的Build Active Architecture Only均设为No

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 02:15:41