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

Xcode单元测试报错:找不到arm64-apple-ios-simulator模块

iOS单元测试架构不匹配问题解决方案

问题定位

报错Could not find module 'MyApp' for target 'arm64-apple-ios-simulator'; found: x86_64-apple-ios-simulator本质是主应用、测试目标与Pods的编译架构不统一——Apple Silicon芯片的模拟器需要arm64架构,但现有配置导致各模块编译出的架构不一致。

修复步骤

1. 统一主应用与测试目标的架构配置

打开Xcode,依次检查主App Target和测试Target的Build Settings:

  • 找到Excluded Architectures:清空所有针对iphonesimulator的手动配置,让Xcode自动适配当前设备架构
  • 找到Build Active Architecture Only:Debug模式设置为YES,Release模式设置为NO
  • 确保两个Target的上述配置完全一致

2. 调整Pods的编译配置

修改Podfile中的post_install脚本,替换原有架构相关配置,确保适配Apple Silicon模拟器:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['SWIFT_VERSION'] = '5.0'
      config.build_settings['ENABLE_BITCODE'] = 'NO'
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
      config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
      
      # 根据模式设置仅编译活跃架构
      config.build_settings['ONLY_ACTIVE_ARCH'] = config.name == 'Debug' ? 'YES' : 'NO'
      # 移除硬编码的arm64排除规则,交由Xcode自动处理
      config.build_settings.delete('EXCLUDED_ARCHS[sdk=iphonesimulator*]')
      
      config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
      config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO'
      config.build_settings['DEVELOPMENT_TEAM'] = '62365DL5L2'
      config.build_settings['CLANG_WARN_STRICT_PROTOTYPES'] = 'NO'
    end
  end
end

3. 清理缓存并重新构建

  • 在终端执行:pod deintegrate && pod install
  • 回到Xcode,按Cmd+Shift+K清理构建缓存,再按Cmd+B编译主应用,最后运行单元测试

4. 验证测试目标依赖

检查测试Target的Build Phases:

  • 确认Target Dependencies中包含主App Target
  • 确认Link Binary With Libraries中正确引入了主App的框架

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 22:35:16