LoginSignup
21
10

More than 3 years have passed since last update.

「react-native run-ios」で「Could not find iPhone X simulator」

Last updated at Posted at 2019-04-02

2019年10月3日追記(krimpedanceさん指摘)

xcode11.0でiPhoneXがリストから消えたようです。
https://github.com/react-native-community/cli/issues/739#issuecomment-533885641

Workaround solution awaiting fix (is was no able to find where is the default in the cli source code…) :
- yarn react-native run-ios --simulator "iPhone 11 Pro Max"
- npx react-native run-ios --simulator "iPhone 11 Pro Max"
- react-native run-ios --simulator "iPhone 11 Pro Max"
- ./node_modules/.bin/react-native run-ios --simulator "iPhone 11 Pro Max"

iPhone 11 Pro Maxなら問題なさそうですね!

2019年9月27日追記

この記事は2019年04月03日に書いたものです。
その時はxcodeを10.2にアップデートしたことが原因でした。

2019年9月20日にxcodeを11.0がリリースされています。
11.0でもビルドできないようです。

botいわくReactNativeのバージョンアップで解決らしい

 "react": "^16.9.0",
 "react-native": "^0.61.1",

詳細はissueをご確認ください。
https://github.com/facebook/react-native/issues/26594

バージョンアップは辛いという方はこちら
https://github.com/facebook/react-native/pull/25146#issuecomment-533995604

概要

昨日までsimulatorが立ち上がったのに、急に立ち上がらなくなった。

~/r/sample ❯❯❯ react-native run-ios
Found Xcode project sample.xcodeproj

Could not find iPhone X simulator

Error: Could not find iPhone X simulator

心当たりは、Xcodeを10.2にアップデートしたこと。

環境

xcode 10.2
ReactNative 0.57.4
※多分0.57.4以外でも発生します。

解決方法

解決策がすでにありました。
https://github.com/facebook/react-native/issues/21498#issuecomment-476621627

パターン1 findMatchingSimulator.jsの書き換え

node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js

42行目~

  if (!version.startsWith('iOS') && !version.startsWith('tvOS')) {
    continue;
  }

下記に書き換え

  if (!version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS') && !version.startsWith('com.apple.CoreSimulator.SimRuntime.tvOS')) {
    continue;
  }

パターン2 ReactNativeのバージョンアップ

0.59.0以上にバージョンアップすると動作します。

ただ、0.59.1にバージョンアップするのに詰まったので、下記を参考にさせていただきました。
https://github.com/saghul/rn-diff/compare/rn-0.57.4...rn-0.59.1

おまけ

ReactNativeのバージョンを変更したくなかったので、findMatchingSimulator.jsの書き換えでいこうと思ったが、
node_modulesをインストールする度に書き換えるのは面倒なのでシェルスクリプトを用意しようと考えた。

gnu-sedをインストール

brew install gnu-sed
#!/bin/sh

rm -rf node_modules
npm install 

gsed -i -e '42d' ./node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
gsed -i -e "42i if (!version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS') && !version.startsWith('com.apple.CoreSimulator.SimRuntime.tvOS')) {" ./node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js

初めてシェルスクリプトを書いたけど置換でいいはず...勉強します。

最後に

Android64bit対応も必要ならこれを機にReactNativeのバージョンを更新した方が幸せになれる気がする

21
10
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
10