自升级到 Xcode 10.2 后,我无法再通过 cli 运行 react-native 运行-ios
Since upgrading to Xcode 10.2 I can no longer run react-native run-ios through the cli
我今天升级到 Xcode 10.2,因为升级后我不能 运行 react-native run-ios
通过 cli:
react-native run-ios --simulator="iPhone X"
Found Xcode workspace a.xcworkspace
Could not find iPhone X simulator
Error: Could not find iPhone X simulator
at resolve (/Users/user/Documents/work/a/a-light-ui/node_modules/react-native/local-cli/runIOS/runIOS.js:149:13)
at new Promise (<anonymous>)
at runOnSimulator (/Users/user/Documents/work/a/a-light-ui/node_modules/react-native/local-cli/runIOS/runIOS.js:134:10)
at Object.runIOS [as func] (/Users/user/Documents/work/a/a-light-ui/node_modules/react-native/local-cli/runIOS/runIOS.js:106:12)
at Promise.resolve.then (/Users/user/Documents/work/a/a-light-ui/node_modules/react-native/local-cli/cliEntry.js:117:22)
如果我运行xcrun simctl list devices
所有模拟器显示(Shutdown) (unavailable, runtime profile not found)
:
iPhone X (7AADFA50-7B57-4A40-8434-9A86F345D7ED) (Shutdown) (unavailable, runtime profile not found)
自从 xcode 升级到 10.2 后,还有其他人遇到过 RN 的这个问题吗?它仍然可以通过 Xcode.. 但这意味着打开 Xcode.
我是这样解决的;
首先,你需要走这条路
node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
然后;
您需要更改此代码
if (!version.startsWith('iOS') && !version.startsWith('tvOS'))
和
if (!version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS') && !version.startsWith('com.apple.CoreSimulator.SimRuntime.tvOS'))
希望对你有所帮助,
参考:https://github.com/facebook/react-native/issues/21498#issuecomment-476621627
你甚至只是做这样的事情
if (version.indexOf('iOS') === -1)
...
此错误自 RN v0.58.0
以来已修复,请参阅提交 here
IIRC 这个错误是在 Xcode 10.1
中引入的
此外,您只需将 startsWith()
替换为 includes()
即可解决此问题。但是每次更新 node_modules
时都这样做并不理想,因此我建议尽可能更新您的 RN 版本。
我想我也会在这里添加我的解决方案,希望能帮助到别人。我刚刚升级到 Mac OS Mojave,我也升级到 Xcode 10.2。我的整个 React Native 项目都崩溃了,真的很糟糕。所以我将 Xcode 降级回 10.1。然后,我开始看到这个错误,在 运行ning react-native 运行-ios:
之后说
Could not find iPhone X simulator
上面的 "hack" 通过使用上面的更新编辑 findMatchingSimulator.js 文件来修复它。
然后,react-native 运行-ios 走得更远,下一个错误是:
:CFBundleIdentifier, does not exist
我通过以下方式解决了这个问题:
- cd node_modules/react-native/third-party/glog* TabEnter
- ./配置
现在 react-native 运行-ios 可以工作了。我希望这对某人有所帮助,这是@ss 的痛苦。
如果在 runSimulator.js.
中替换以下代码行后,如果找不到模拟器仍然存在
Path for runSimulator.js -> /node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
if (!version.startsWith('iOS') && !version.startsWith('tvOS')) { continue; }
用这个
if ( !version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS') && !version.startsWith('com.apple.CoreSimulator.SimRuntime.tvOS') ) { continue; }
替换后评论以下行
if ( simulator.availability !== '(available)' && simulator.isAvailable !== 'YES' ) { continue; }
and 2nd approach after updating to XCode 11
Xcode 11 xcrun returns true 或 false 而不是 isAvailable 属性 之前的 YES 或 NO。您可以使用以下命令检查
xcrun simctl list devices --json
above command will print all available devices like following
com.apple.CoreSimulator.SimRuntime.iOS-12-2" : [
{
"state" : "Booted",
"isAvailable" : true,
"name" : "iPhone X",
"udid" : "E53748D1-628B-4A99-A419-4D7AE7CE4745"
}
]
Replace YES with true in the following code
if ( simulator.availability !== '(available)' && simulator.isAvailable !== 'YES' ) { continue; }
像这样
if ( simulator.availability !== '(available)' && simulator.isAvailable !== true ) { continue; }
我今天升级到 Xcode 10.2,因为升级后我不能 运行 react-native run-ios
通过 cli:
react-native run-ios --simulator="iPhone X"
Found Xcode workspace a.xcworkspace
Could not find iPhone X simulator
Error: Could not find iPhone X simulator
at resolve (/Users/user/Documents/work/a/a-light-ui/node_modules/react-native/local-cli/runIOS/runIOS.js:149:13)
at new Promise (<anonymous>)
at runOnSimulator (/Users/user/Documents/work/a/a-light-ui/node_modules/react-native/local-cli/runIOS/runIOS.js:134:10)
at Object.runIOS [as func] (/Users/user/Documents/work/a/a-light-ui/node_modules/react-native/local-cli/runIOS/runIOS.js:106:12)
at Promise.resolve.then (/Users/user/Documents/work/a/a-light-ui/node_modules/react-native/local-cli/cliEntry.js:117:22)
如果我运行xcrun simctl list devices
所有模拟器显示(Shutdown) (unavailable, runtime profile not found)
:
iPhone X (7AADFA50-7B57-4A40-8434-9A86F345D7ED) (Shutdown) (unavailable, runtime profile not found)
自从 xcode 升级到 10.2 后,还有其他人遇到过 RN 的这个问题吗?它仍然可以通过 Xcode.. 但这意味着打开 Xcode.
我是这样解决的;
首先,你需要走这条路
node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
然后;
您需要更改此代码
if (!version.startsWith('iOS') && !version.startsWith('tvOS'))
和
if (!version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS') && !version.startsWith('com.apple.CoreSimulator.SimRuntime.tvOS'))
希望对你有所帮助,
参考:https://github.com/facebook/react-native/issues/21498#issuecomment-476621627
你甚至只是做这样的事情
if (version.indexOf('iOS') === -1)
...
此错误自 RN v0.58.0
以来已修复,请参阅提交 here
IIRC 这个错误是在 Xcode 10.1
此外,您只需将 startsWith()
替换为 includes()
即可解决此问题。但是每次更新 node_modules
时都这样做并不理想,因此我建议尽可能更新您的 RN 版本。
我想我也会在这里添加我的解决方案,希望能帮助到别人。我刚刚升级到 Mac OS Mojave,我也升级到 Xcode 10.2。我的整个 React Native 项目都崩溃了,真的很糟糕。所以我将 Xcode 降级回 10.1。然后,我开始看到这个错误,在 运行ning react-native 运行-ios:
之后说Could not find iPhone X simulator
上面的 "hack" 通过使用上面的更新编辑 findMatchingSimulator.js 文件来修复它。
然后,react-native 运行-ios 走得更远,下一个错误是:
:CFBundleIdentifier, does not exist
我通过以下方式解决了这个问题:
- cd node_modules/react-native/third-party/glog* TabEnter
- ./配置
现在 react-native 运行-ios 可以工作了。我希望这对某人有所帮助,这是@ss 的痛苦。
如果在 runSimulator.js.
中替换以下代码行后,如果找不到模拟器仍然存在Path for runSimulator.js -> /node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
if (!version.startsWith('iOS') && !version.startsWith('tvOS')) { continue; }
用这个
if ( !version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS') && !version.startsWith('com.apple.CoreSimulator.SimRuntime.tvOS') ) { continue; }
替换后评论以下行
if ( simulator.availability !== '(available)' && simulator.isAvailable !== 'YES' ) { continue; }
and 2nd approach after updating to XCode 11
Xcode 11 xcrun returns true 或 false 而不是 isAvailable 属性 之前的 YES 或 NO。您可以使用以下命令检查
xcrun simctl list devices --json
above command will print all available devices like following
com.apple.CoreSimulator.SimRuntime.iOS-12-2" : [
{
"state" : "Booted",
"isAvailable" : true,
"name" : "iPhone X",
"udid" : "E53748D1-628B-4A99-A419-4D7AE7CE4745"
}
]
Replace YES with true in the following code
if ( simulator.availability !== '(available)' && simulator.isAvailable !== 'YES' ) { continue; }
像这样
if ( simulator.availability !== '(available)' && simulator.isAvailable !== true ) { continue; }