无需Rosetta修复CircleCI Apple Silicon iOS测试启动失败问题
问题
我有一个原生iOS应用,使用CircleCI的Apple Silicon节点进行CI/CD。当不启用Rosetta时,运行模拟器单元测试会触发**"Failed to install or launch the test runner"**错误。以下是我的配置文件及错误日志,求不依赖Rosetta的解决方案。
config.yml配置
version: 2.1 # setup: true orbs: macos: circleci/macos@2.4.1 ruby: circleci/ruby@2.1.2 parameters: application-nonprod-context: description: Context containing credentials for nonprod type: string default: application-nonprod-context-default-value executors: my-executor: macos: xcode: "15.3.0" resource_class: macos.m1.large.gen1 commands: setup: description: Setup common to all jobs steps: - checkout - ruby/install-deps jobs: run-tests: executor: my-executor steps: - setup - macos/install-rosetta - macos/preboot-simulator: device: iPhone 15 Pro version: "17.4" - run: name: Run unit tests using Fastlane command: bundle exec fastlane tests workflows: code-changed: jobs: - run-tests: context: << pipeline.parameters.application-nonprod-context >> filters: branches: only: /.*/
Fastfile配置
# This file contains the fastlane.tools configuration # You can find the documentation at https://docs.fastlane.tools # # For a list of all available actions, check out # # https://docs.fastlane.tools/actions # # For a list of all available plugins, check out # # https://docs.fastlane.tools/plugins/available-plugins # # Uncomment the line if you want fastlane to automatically update itself # update_fastlane default_platform :ios platform :ios do before_all do setup_circle_ci end desc "Run unit tests using scheme UnitTests" lane :tests do run_tests(workspace: "MyProject.xcworkspace", devices: ["iPhone 15 Pro (17.4)"], scheme: "UnitTests", clean: true, parallel_testing: false, configuration: "Debug", derived_data_path: ".Build") end end
错误日志
Testing failed: Simulator device failed to launch com.mycompany.myapp.debug. MyApp encountered an error (Failed to install or launch the test runner. (Underlying Error: Simulator device failed to launch com.mycompany.myapp.debug. No such process. (Underlying Error: Application launch for 'com.mycompany.myapp.debug' did not return a process handle nor launch error. No such process)))
不依赖Rosetta的解决方案
1. 修正项目架构配置
- 打开Xcode进入项目Target的Build Settings:
- 将
Architectures设置为Standard Architectures (arm64),移除x86_64架构 - 确保
Build Active Architecture Only在Debug模式下设为Yes - 若存在
VALID_ARCHS配置,仅保留arm64
- 将
2. 调整CircleCI配置
- 删除
config.yml中的- macos/install-rosetta步骤,完全禁用Rosetta - 替换
macos/preboot-simulator为手动启动命令,确保模拟器以arm64架构运行:- run: name: Boot arm64 simulator command: | xcrun simctl boot "iPhone 15 Pro (17.4)" xcrun simctl list devices | grep Booted
3. 更新Fastlane测试配置
- 在
run_tests命令中添加destination参数,明确指定arm64架构:lane :tests do run_tests( workspace: "MyProject.xcworkspace", devices: ["iPhone 15 Pro (17.4)"], scheme: "UnitTests", clean: true, parallel_testing: false, configuration: "Debug", derived_data_path: ".Build", build_for_testing: true, destination: "platform=iOS Simulator,name=iPhone 15 Pro,OS=17.4,arch=arm64" ) end
4. 添加缓存清理步骤
- 在CircleCI测试步骤前添加缓存清理,避免旧架构构建残留:
- run: name: Clean simulator and derived data command: | xcrun simctl erase all rm -rf ~/Library/Developer/Xcode/DerivedData/*
5. 验证Xcode与模拟器兼容性
- 确认Xcode 15.3已正确安装iOS 17.4模拟器包,若存在兼容性问题,升级Xcode到最新稳定版本
内容的提问来源于stack exchange,提问作者ThE uSeFuL
相关产品推荐
相关产品推荐

