启动模拟器时 xcodebuild 超时

xcodebuild times out when starting simulator

我正在尝试使用 TeamCity 为我的 iOS 应用设置自动化测试。目前,我的代理正在构建,但是一旦构建了最后一个目标并 运行ning 代码签名,它就会挂起并显示以下内容:

[19:29:34][CodeSign] CodeSign /var/root/Library/Developer/Xcode/DerivedData/MyProductiOS-fgkoogiimhlbckdlbckzmqfyaoff/Build/Products/Debug-iphonesimulator/MyProductiOSUITests-Runner.app/PlugIns/MyProductiOSUITests.xctest
[19:29:34][CodeSign]     cd /Users/ericmiller/.tcagent/work/f9abef315a0137d4
[19:29:34][CodeSign]     export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
[19:29:34][CodeSign]     export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/Users/ericmiller/.pyenv/shims:/Users/ericmiller/.rbenv/shims:/Users/ericmiller/.pyenv/shims:/Users/ericmiller/Scripts:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/opt/local/bin"
[19:29:34][CodeSign] Signing Identity:     "-"
[19:29:34][CodeSign]     /usr/bin/codesign --force --sign - --timestamp=none /var/root/Library/Developer/Xcode/DerivedData/MyProductiOS-fgkoogiimhlbckdlbckzmqfyaoff/Build/Products/Debug-iphonesimulator/MyProductiOSUITests-Runner.app/PlugIns/MyProductiOSUITests.xctest
[19:29:34][CodeSign] /var/root/Library/Developer/Xcode/DerivedData/MyProductiOS-fgkoogiimhlbckdlbckzmqfyaoff/Build/Products/Debug-iphonesimulator/MyProductiOSUITests-Runner.app/PlugIns/MyProductiOSUITests.xctest: replacing existing signature
[19:31:32][CodeSign] 2017-01-22 19:31:32.279 xcodebuild[28262:86807]  iOSSimulator: Timed out waiting 120 seconds for simulator to boot, current state is 1.
[19:31:32][CodeSign] 2017-01-22 19:31:32.290 xcodebuild[28262:86805]  iOSSimulator: Timed out waiting 120 seconds for simulator to boot, current state is 1.
[19:31:32][CodeSign] 2017-01-22 19:31:32.291 xcodebuild[28262:86797] Error Domain=IDETestOperationsObserverErrorDomain Code=3 "Timed out waiting 120 seconds for simulator to boot, current state is 1. If you believe this error represents a bug, please attach the log file at /var/root/Library/Developer/Xcode/DerivedData/MyProductiOS-fgkoogiimhlbckdlbckzmqfyaoff/Logs/Test/89F7C786-9E91-419F-98CA-F36385618DC2/Session-MyProductiOSTests-2017-01-22_192932-E95vcV.log" UserInfo={NSLocalizedDescription=Timed out waiting 120 seconds for simulator to boot, current state is 1. If you believe this error represents a bug, please attach the log file at /var/root/Library/Developer/Xcode/DerivedData/MyProductiOS-fgkoogiimhlbckdlbckzmqfyaoff/Logs/Test/89F7C786-9E91-419F-98CA-F36385618DC2/Session-MyProductiOSTests-2017-01-22_192932-E95vcV.log}
[19:31:32][CodeSign] 2017-01-22 19:31:32.291 xcodebuild[28262:86797] Error Domain=IDETestOperationsObserverErrorDomain Code=3 "Timed out waiting 120 seconds for simulator to boot, current state is 1. If you believe this error represents a bug, please attach the log file at /var/root/Library/Developer/Xcode/DerivedData/MyProductiOS-fgkoogiimhlbckdlbckzmqfyaoff/Logs/Test/89F7C786-9E91-419F-98CA-F36385618DC2/Session-MyProductiOSUITests-2017-01-22_192932-mrX7wQ.log" UserInfo={NSLocalizedDescription=Timed out waiting 120 seconds for simulator to boot, current state is 1. If you believe this error represents a bug, please attach the log file at /var/root/Library/Developer/Xcode/DerivedData/MyProductiOS-fgkoogiimhlbckdlbckzmqfyaoff/Logs/Test/89F7C786-9E91-419F-98CA-F36385618DC2/Session-MyProductiOSUITests-2017-01-22_192932-mrX7wQ.log}

模拟器应用程序已在 Dock 中打开。单击模拟器没有任何反应,但如果我右键单击并 select window,我可以看到模拟器确实 运行ning 但没有显示任何内容。 Example

我正在寻找一种解决方法来测试我的代码,如果可能的话,无需切换到物理设备而不是模拟器。我怎样才能实现这个目标,我的配置可能有什么问题?

编辑:

Sven Driemecker 找到了解决方案。这是我的配置。 在 运行 构建 xcode 之前,我 运行 下面的 shell 脚本来确保一个卫生的测试环境。

xcrun simctl shutdown %env.simulator_guid%
killall Simulator
killall com.apple.CoreSimulator.CoreSimulatorService
xcrun simctl erase %env.simulator_guid%

然后,当运行编译xcodebuild时,添加以下选项:

-destination "id=%env.simulator_guid%"

最后,清理一切:

xcrun simctl shutdown %env.simulator_guid%
killall Simulator
killall com.apple.CoreSimulator.CoreSimulatorService

更新:这是关于如何为 XCode/iOS.

设置基本 TeamCity CI 的 blog post I wrote

这看起来很奇怪,但简单地重置模拟器通常可以解决这个问题。我们经常在自己的 CI-系统上遇到同样的错误。

尝试 Simulator-Menu -> Reset Content and Settings,然后重启模拟器。

您可以在命令行上执行此操作,但我不推荐这样做,因为它会显着降低您的构建速度。

只是 杀死 重新打开 模拟器对我有用。

我在 Xcode 11.3.1 的模拟器中尝试 运行 一个 iOS 应用程序时遇到了类似的错误。我发现重新选择虚拟硬件可以比本页提到的其他解决方案更快地解决这个问题。

当我在 Xcode 中收到 "Timed out waiting for Simulator.app to become ready" 错误时,Simulator.app 通常已启动但未显示实际模拟器。选择 Hardware > Device > [OS version] -> [Simulator Name] 会导致模拟器出现并在下一次 运行 尝试时成功启动我的应用程序。

Xcode 11.3 及更早版本中存在一个错误,如果您从另一个 Xcode 获得 Simulator.app 运行,则可能会以这种方式出现。有一场小型比赛 window 可能会发生这种情况。 Xcode 11.3.1.

中已修复

但是...

Xcode 11.3.1 及更高版本(通过 Xcode 11.4.1 作为此评论)中存在一个错误,它也以这种方式表现出来。要解决此问题,您可以在 Dock 启动后单击 Simulator.app(即使它在前台)。或者,您可以通过 'Edit -> Automatically Sync Pasteboard'.

在 Simulator.app 中启用粘贴板同步

我还没有找到解决此问题根本原因的好方法,但我找到了解决方法。如果您在 Xcode 中构建您的应用程序之前只是打开模拟器,则可以绕过此问题。

您还可以查看模拟器应用程序的 Window 菜单。

可能有一个或多个模拟器 windows 被标记为使用 [External Display]。当您从菜单中 select 一个 window 时,什么都不会出现,但是您可以按 Cmd-W 将其关闭。

使用外部显示器关闭所有 windows 后,模拟器将再次开始正常工作。

我不确定如何 select 一个模拟器的外接显示器,但是我遇到过几次,只是退出模拟器应用程序并没有帮助。我必须按照上面的描述进行操作,或者重新启动机器。