fastlane: Simulator is not started

Original issue by @yakimant - Imported from fastlane/scan#26

I’ve got this issue: 2015-10-30 16:56:05.815 xcodebuild[53793:347720] iPhoneSimulator: Timed out waiting 120 seconds for simulator to boot, current state is 1.

I’ve got it before tunning xcodebuild (xctool didn’t have this issue). It is solved by running the simulatore (instrument -w or ios-sim).

But maybe it can be solved inside scan?

Appreciate you work!

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 24 (16 by maintainers)

Most upvoted comments

I use a slightly modified version that accepts the device name as parameter:

#!/bin/bash

if [ "$1" = "" ]; then
    echo "Usage: launch-ios-simulator.sh <device name>"
    exit 1;
fi

device="$1"
printf "Closing any open instances of the iphone simulator...\n"
killall "Simulator" || true
printf "Determining latest iOS simulator...\n"
latest_ios=$(xcodebuild -showsdks | grep -Eo "iphonesimulator(.+)" | tail -1)
latest_ios=${latest_ios##iphonesimulator}
printf "Detected latest iOS simulator version: ${latest_ios}\n"
printf "Pre-Launching iphone simulator for ${device} (${latest_ios})\n"
simulator_id=$(xcrun instruments -s | grep -Eo "${device} \(${latest_ios}\) \[.*\]" | grep -Eo "\[.*\]" | sed "s/^\[\(.*\)\]$/\1/")
open -b com.apple.iphonesimulator --args -CurrentDeviceUDID $simulator_id

RETVALUE=$?
if [ "$RETVALUE" != "0" ]; then
   printf "Something went wrong when attempting to launch the simulator for ${device} (${latest_ios})\n"
   exit 1;
fi 
printf "Simulator launched for ${device} (${latest_ios})\n"

Sample usage:

 before_all do
    ENV["FASTLANE_XCODE_LIST_TIMEOUT"] = "120"
    sh "./launch-ios-simulator.sh 'iPad Air 2'"
 end

This works well for me. No more stalling builds.

@nitinalabur Just a quick addition: if your simulator is not running yet, the script will fail because killall returns 1. If you change it to this it will work: killall "Simulator" || true

I have a solution that works for me. I was trying to run scan from Jenkins on a mac mini server, and would often have the issue (“Timed out waiting for 120 seconds…”).

Problem was with the current selected iOS simulator (if you were to launch the app on mac through spotlight or finder) not matching the device I was setting for Scan.

Here’s the fastlane lane I run on jenkins

desc "Runs all the tests"
  lane :test do
    scan( scheme: "MyTestTarget",
          device: "iPhone 4s",  # <-- should match the current 'selected device' in jenkins' simulator 
                                #     (Simulator-> Hardware -> Device -> iOS -> iPhone 4s)
          clean: true)
  end

If the iOS simulator is set to iPhone 4s and the device selected in the Scan:Device parameter is iPhone 4s, no issues.

So, before running any fastlane commands on Jenkins, I run this shell script

printf "Closing any open instances of the iphone simulator...\n"
killall "Simulator"
printf "Determining latest iOS simulator...\n"
latest_ios=$(xcodebuild -showsdks | grep -Eo "iphonesimulator(.+)" | tail -1)
latest_ios=${latest_ios##iphonesimulator}
printf "Detected latest iOS simulator version: ${latest_ios}\n"
printf "Pre-Launching iphone simulator for iPhone 4s (${latest_ios})\n"
simulator_id=$(xcrun instruments -s | grep -Eo "iPhone 4s \(${latest_ios}\) \[.*\]" | grep -Eo "\[.*\]" | sed "s/^\[\(.*\)\]$/\1/")
open -b com.apple.iphonesimulator --args -CurrentDeviceUDID $simulator_id

RETVALUE=$?
if [ "$RETVALUE" != "0" ]; then
   printf "Something went wrong when attempting to launch the simulator for iPhone 4s (${latest_ios})\n"
   exit 1;
fi 
printf "Simulator launched for iPhone 4s (${latest_ios})\nStarting build...\n"

fastlane ios test

the above code is just a slight variation (iPhone type) based on jasontaft’s super helpful code/comment here . if you wish to use a simulator for any other device, all you need to do is make the tweak I made.

With this, when I hit “Build Now”, it runs my ‘ios test’ lane as expected, without any hiccups. Hope this helps!

@nitinalabur Thanks so much for sharing. I’m glad to hear you are up and running. Hope that you have a wonderful week!

Something I have noticed as to why this happens: if the CI simulator is not matching that of your fastfile/scanfile (e.g., CI has it set as iPhone 4S and your Fastlane sets it as 5s) this issue persists.

When you run scan/Fastlane on your local machine, whichever hardware pops up in your iOS simulator, set that as the device to test against in your scan/fast file