React-native: CLI: Running on iOS failed (can't find simulator)

Created on 29 Mar 2019  ·  12Comments  ·  Source: facebook/react-native

🐛 Bug Report

I'm creating this because the comments I found are on a closed issue.

Running run-ios gives:

Could not find iPhone X simulator

I've updated the xcode cli tools yesterday, so for me that might have something to do with it.

Expected Behavior

No error.

More

https://github.com/facebook/react-native/issues/23282#issuecomment-476439080

This fix works but is obviously not the way forward.

Environment

React Native Environment Info:
System:
OS: macOS 10.14.4
CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
Memory: 6.25 GB / 32.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 10.12.0 - ~/.nvm/versions/node/v10.12.0/bin/node
Yarn: 1.13.0 - /usr/local/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v10.12.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
Android SDK:
API Levels: 21, 22, 23, 24, 25, 26, 27, 28
Build Tools: 27.0.3, 28.0.3
System Images: android-25 | Google Play Intel x86 Atom, android-27 | Google Play Intel x86 Atom, android-28 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.2 AI-181.5540.7.32.5014246
Xcode: 10.2/10E125 - /usr/bin/xcodebuild
npmPackages:
react: 16.6.3 => 16.6.3
react-native: 0.58.3 => 0.58.3

Bug iOS Locked

Most helpful comment

A quick fix for this issue is to update the if statement inside
./node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
to be
if (!version.includes('iOS') && !version.includes('tvOS')) {

All 12 comments

It looks like you are using an older version of React Native. Please update to the latest release, v0.59 and verify if the issue still exists.

The "Resolution: Old Version" label will be removed automatically once you edit your original post with the results of running react-native info on a project using the latest release.

Verified that it _does_ work when I update to latest. Maybe a patch for those that are on older versions?

I am having this same issue after latest Mojave update from 10.14.3 to 10.14.4 . After update I ended up with Xcode 12.2 and I am now having this issue. Also, Appium is unable to find iOS emulators also. I just tried downgrading XCode to 12.1, which was working for me yesterday, and it made no difference. I don't have the option to upgrade to 0.59 yet (not for maybe 2 weeks until my dev team is ready). After downgrade, this is my setup:

09:09 $ react-native info

  React Native Environment Info:
    System:
      OS: macOS 10.14.4
      CPU: x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
      Memory: 3.79 GB / 16.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 10.13.0 - ~/.nvm/versions/node/v10.13.0/bin/node
      Yarn: 1.15.2 - /usr/local/bin/yarn
      npm: 6.4.1 - ~/.nvm/versions/node/v10.13.0/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
      Android SDK:
        Build Tools: 27.0.3, 28.0.3
        API Levels: 26, 27, 28
    IDEs:
      Android Studio: 3.3 AI-182.5107.16.33.5264788
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.6.3 => 16.6.3 
      react-native: 0.57.8 => 0.57.8 
    npmGlobalPackages:
      react-native-cli: 2.0.1

A quick fix for this issue is to update the if statement inside
./node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
to be
if (!version.includes('iOS') && !version.includes('tvOS')) {

A quick fix for this issue is to update the if statement inside
./node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
to be
if (!version.includes('iOS') && !version.includes('tvOS')) {

I tried that but it still fails. Not sure why. I don't think that if-condition matters in my case since iOS never appears in either command below.

09:53 $ instruments -s devices | grep 'iPhone X'
iPhone X (12.1) [391778F2-0E7F-4D41-9802-C971BC9B35E9] (Simulator)
iPhone XR (12.1) [FDE02A28-2061-48FF-8FF1-3B762B4F4E10] (Simulator)
iPhone XS (12.1) [AEA0502C-2984-4622-AB99-F6B65316CFE1] (Simulator)
...
09:55 $ xcrun simctl list devices | grep 'iPhone X'
    iPhone X (391778F2-0E7F-4D41-9802-C971BC9B35E9) (Booted) 
    iPhone XS (AEA0502C-2984-4622-AB99-F6B65316CFE1) (Shutdown) 
    iPhone XS Max (265B91EB-C8CE-4F2F-B555-F450DB5CEBBE) (Shutdown)
...

React native is using xcrun simctl list --json devicesto get the devices list
and it seems like it format of the key got changed:
{ "devices" : { "com.apple.CoreSimulator.SimRuntime.iOS-11-4" : [ { "availability" : "(available)",
as in the origintal if statement uses startsWith which doesn't seem to be able to work for this com.apple.CoreSimulator.SimRuntime.iOS-11-4 type of the key.
so replacing startsWith with includes should resolve the problem, at least for me.

Wierd, here is what I have , which is very different than what you are saying above:

09:59 $ xcrun simctl list --json devices | grep -A 3 -B 4 "iPhone X\""
      {
        "availability" : "(unavailable, runtime profile not found)",
        "state" : "Shutdown",
        "isAvailable" : false,
        "name" : "iPhone X",
        "udid" : "1EA56A4B-40DE-44A8-9C4F-CD9388560ADC",
        "availabilityError" : "runtime profile not found"
      },
--
--
      {
        "availability" : "(unavailable, runtime profile not found)",
        "state" : "Shutdown",
        "isAvailable" : false,
        "name" : "iPhone X",
        "udid" : "D9AAE0BA-58F3-4C4E-B488-2D0A1F09DBA6",
        "availabilityError" : "runtime profile not found"
      },
--
--
      {
        "availability" : "(available)",
        "state" : "Booted",
        "isAvailable" : true,
        "name" : "iPhone X",
        "udid" : "391778F2-0E7F-4D41-9802-C971BC9B35E9",
        "availabilityError" : ""
      },

@augustl - I just don't use grep, those are just 3 first lines of the output.

Thanks @alexsergeev . I got it working with above suggestion of using !version.includes('iOS'). I think I previously thought it was not working because I didn't save the change in the file. Thanks. Verified this fix works.

This is already fixed in react-native-cli in master branch, not a stable release yet.

https://github.com/react-native-community/react-native-cli/pull/274

@jherencia It works!

If you wish not to upgrade your react-native version, patch files in postinstall step.

echo "Patching Xcode 10.2 CLI introduced breaking changes"
sed -i '' "s/version.indexOf('iOS') !== 0/\!version.includes('iOS') \&\& \!version.includes('tvOS')/" ./node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js

Credits to @alexsergeev

Was this page helpful?
0 / 5 - 0 ratings