iOS项目Github Actions构建失败:请求设备未找到问题求助
解决Github Actions中iOS构建找不到模拟器的问题
问题根源
- YAML配置语法错误:工作流配置存在缩进问题,
pull_request块未正确嵌套在on节点下,build-and-test任务的runs-on和steps也未正确缩进,会导致工作流执行异常。 - 指定模拟器环境不存在:
macos-latest默认的Xcode版本可能未预装iOS 15.2模拟器,或Xcode选择命令未指向包含该模拟器的版本。
修复步骤
1. 修正YAML配置缩进
先将配置文件调整为正确的缩进格式:
name: Pull Request on: push: branches: - main pull_request: branches: - main jobs: build-and-test: runs-on: macos-latest steps: - uses: actions/checkout@v2 - name: Select Xcode run: sudo xcode-select -switch /Applications/Xcode.app - name: Build and test run: xcodebuild clean build test -project GithubActionsConfiguration.xcodeproj -scheme "CI" -sdk iphonesimulator -destination "platform=iOS Simulator,name=iPhone 11" ONLY_ACTIVE_ARCH=NO
2. 解决模拟器不存在问题
提供三种可行方案:
方案一:使用通用模拟器目标(推荐)
移除命令中的OS=15.2限制,让xcodebuild自动匹配环境中可用的iPhone 11模拟器:
xcodebuild clean build test -project GithubActionsConfiguration.xcodeproj -scheme "CI" -sdk iphonesimulator -destination "platform=iOS Simulator,name=iPhone 11" ONLY_ACTIVE_ARCH=NO
方案二:指定对应Xcode版本
若必须使用iOS 15.2模拟器,可指定预装该版本的Xcode 13.2.1,通过setup-xcode action配置:
- name: Setup Xcode 13.2.1 uses: maxim-lobanov/setup-xcode@v1 with: xcode-version: '13.2.1'
配置完成后保留原构建命令即可。
方案三:手动创建指定版本模拟器
如果需要在新版Xcode中使用旧版本模拟器,可先安装并创建对应模拟器:
- name: Install iOS 15.2 Simulator run: | xcodebuild -downloadPlatform iOS xcrun simctl create "iPhone 11 (15.2)" com.apple.CoreSimulator.SimDeviceType.iPhone-11 com.apple.CoreSimulator.SimRuntime.iOS-15-2
执行完此步骤后再运行构建命令。
3. 验证效果
修改配置后重新触发工作流,检查是否能成功匹配模拟器并完成构建。
内容的提问来源于stack exchange,提问作者Tung Vu Duc
相关产品推荐
相关产品推荐

