Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xcodebuild times out when starting simulator

I am attempting to set up automated testing for my iOS app using TeamCity. Currently, my agent builds, but once building the last target and running codesign, it hangs and displays the following:

[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}

The simulator app is open in the dock. Clicking on the simulator does nothing, but if I right-click and select the window, I can see that the simulator is indeed running but is not displaying anything. Example

I'm looking for a workaround to test my code, without switching to a physical device instead of a simulator if possible. How can I achieve this goal, and what could be wrong with my configuration?

Screenshot

EDIT:

Sven Driemecker found the solution. Here's my configuration. Before running the xcodebuild, I run the following shell script to ensure a sanitary testing environment.

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

Then, when running the xcodebuild, add the following option:

-destination "id=%env.simulator_guid%"

And finally, to clean everything up:

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

Update: Here's a blog post I wrote about how to set up basic TeamCity CI for XCode/iOS.

like image 950
Eric Miller Avatar asked Jan 23 '17 01:01

Eric Miller


3 Answers

I have been experiencing a similar error when attempting to run an iOS app in the simulator from Xcode 11.3.1. I have found that re-choosing the virtual hardware can resolve this issue a little quicker than other solutions mentioned on this page.

When I receive the "Timed out waiting for Simulator.app to become ready" error in Xcode, the Simulator.app has typically launched but shows no actual simulator. Choosing Hardware > Device > [OS version] -> [Simulator Name] causes the simulator to appear and successfully launch my app on the next run attempt.

like image 130
Jaysen Marais Avatar answered Oct 07 '22 14:10

Jaysen Marais


It seems pretty odd, but simply resetting the simulator usually fixes this. We often encounter the same error on our own CI-system.

Try Simulator-Menu -> Reset Content and Settings, then restart the simulator.

You can enforce this on the command line, but I won't recommend it, cause it will slow down your build remarkably.

like image 23
Sven Driemecker Avatar answered Oct 07 '22 13:10

Sven Driemecker


There is a bug in Xcode 11.3 and earlier which could manifest this way if you have Simulator.app running from another Xcode. There is a small race window in which this could happen. That was fixed in Xcode 11.3.1.

but...

There is a bug in Xcode 11.3.1 and later (through Xcode 11.4.1 as of this comment) which manifests this way as well. To workaround the issue, you can click on Simulator.app in Dock after it launches (even if it is foreground). Alternatively, you can enable pasteboard synchronization in Simulator.app via 'Edit -> Automatically Sync Pasteboard'.

like image 41
Jeremy Huddleston Sequoia Avatar answered Oct 07 '22 15:10

Jeremy Huddleston Sequoia