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

iOS项目Github Actions构建失败:请求设备未找到问题求助

解决Github Actions中iOS构建找不到模拟器的问题

问题根源

  1. YAML配置语法错误:工作流配置存在缩进问题,pull_request 块未正确嵌套在 on 节点下,build-and-test 任务的 runs-on 和 steps 也未正确缩进,会导致工作流执行异常。
  2. 指定模拟器环境不存在: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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 00:57:48