12

It's a common case to run tests against different versions of iOS simulators/SDKs on CI. However, only the latest iOS simulator is installed by Xcode on default.

So I need install other missing iOS simulators from command line in CI environment. But I cannot find a way to install those simulators from command line.

ipraba
  • 16,485
  • 4
  • 59
  • 58
Quanlong
  • 24,028
  • 16
  • 69
  • 79

5 Answers5

26

It can be done with xcode-install, with the following commands

gem install xcode-install
xcversion simulators --install='iOS 9.3'
Quanlong
  • 24,028
  • 16
  • 69
  • 79
  • 1
    If you need to do this in your CI and handle the password prompt, try: echo "" | xcversion simulators --install='iOS 10.3.1' – jwswart Jul 20 '17 at 14:05
  • for some reason it doesn't work for me, i have Xcode 10.1 and xcversion 2.5.0. The output is `Installing iOS 11.2 Simulator for Xcode 10.1.0... [!] Failed to download iOS 11.2 Simulator.` – olyv Feb 21 '19 at 12:29
  • Sadly, this doesn't seem work anymore under XCode 14.1. – andred Nov 03 '22 at 16:26
5
xcrun simctl create <name> <device type> <runtime>

For example:

xcrun simctl create "ry" "iPhone 11 Pro Max" iOS13.3  

xcrun simctl is command utils to control iOS simulator, just like adb for Android. You can also run xcrun simctl help, there are a bundle of useful subcommands. When successful, most of these commands exit with 0; when failed, most exit with a non-zero number.

Personally, I have an article about how to use simulator from terminal.

RY_ Zheng
  • 3,041
  • 29
  • 36
1

FYI

All simulators are packed with Xcode app. Instead of installing simulators you can just install the specific Xcode versions. Xcode7.0 has iOS9 Simulators Xcode6.4 has iOS8.x Simulators

In your CI testing if you want to test you app for a specific simulator just select xcode version before you do the xcodebuild command

xcode-select -switch <path to your xcode app>

This will set your default xcode to run the xcodebuild Then run the xcodebuild with your respective simulator.

xcodebuild -configuration ${BUILD_TYPE} -target ${TARGET_NAME} -arch ${CPU_ARCHITECTURE} -sdk ${SIMULATOR_OR_IOS_SDK} 

In the place of SIMULATOR_OR_IOS_SDK give your simulator value.

You can find the simulator value by running

xcodebuild -showsdks

This will show like

OS X SDKs:
    OS X 10.11                      -sdk macosx10.11

iOS SDKs:
    iOS 9.1                         -sdk iphoneos9.1

iOS Simulator SDKs:
    Simulator - iOS 9.1             -sdk iphonesimulator9.1

tvOS SDKs:
    tvOS 9.0                        -sdk appletvos9.0

tvOS Simulator SDKs:
    Simulator - tvOS 9.0            -sdk appletvsimulator9.0

watchOS SDKs:
    watchOS 2.0                     -sdk watchos2.0

watchOS Simulator SDKs:
    Simulator - watchOS 2.0         -sdk watchsimulator2.0

This way you can build your project on any specific device/simulator/os.

Hope this helps :)

ipraba
  • 16,485
  • 4
  • 59
  • 58
  • It's hard to install Xcode from command line, and Xcode.dmg is very large. – Quanlong Dec 28 '15 at 13:29
  • @Quanlong: In a CI environment Xcode is the software that has to be manually installed. Your CI build invocation should use the xcode commandline tools(xcodebuild) to build your app. – ipraba Dec 28 '15 at 13:35
  • Yes, but we have only one version Xcode installed on CI. And some older versions Xcode cannot be installed on newer OS X. – Quanlong Dec 28 '15 at 13:38
  • In that case i would prefer you to install latest xcode and install simulators manually like this. http://stackoverflow.com/questions/32137582/how-to-install-ios-7-and-onwards-simulators-in-xcode-7-beta-5 – ipraba Dec 28 '15 at 13:48
  • I have no GUI interface in CI – Quanlong Dec 28 '15 at 13:51
0
  1. Download a simulator .dmg file from the Apple Developer Portal
  2. Install the simulator using a command: xcrun simctl runtime add <path to DMG file>
zepar
  • 155
  • 7