升级到 Xcode 10.2 后,我无法再通过 cli 运行 react-native run-ios
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/55363698/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Since upgrading to Xcode 10.2 I can no longer run react-native run-ios through the cli
提问by smj2393
I upgraded to Xcode 10.2 today, since upgrading I can't 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)
If I run xcrun simctl list devices
all of the simulators show (Shutdown) (unavailable, runtime profile not found)
:
如果我运行xcrun simctl list devices
所有的模拟器显示(Shutdown) (unavailable, runtime profile not found)
:
iPhone X (7AADFA50-7B57-4A40-8434-9A86F345D7ED) (Shutdown) (unavailable, runtime profile not found)
Has anyone else had this issue with RN since upgrading xcode to 10.2? It still works through Xcode.. but that means opening Xcode.
自从将 xcode 升级到 10.2 以来,有没有其他人在 RN 上遇到过这个问题?它仍然可以通过 Xcode 工作……但这意味着打开 Xcode。
回答by Abdullah K.
I solved like this ;
我是这样解决的;
Firstly, you need to go this path
首先,你需要走这条路
node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
and then;
进而;
You need to change this code
您需要更改此代码
if (!version.startsWith('iOS') && !version.startsWith('tvOS'))
with
和
if (!version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS') && !version.startsWith('com.apple.CoreSimulator.SimRuntime.tvOS'))
I hope, it will be helpful,
我希望它会有所帮助
ref : https://github.com/facebook/react-native/issues/21498#issuecomment-476621627
参考:https: //github.com/facebook/react-native/issues/21498#issuecomment-476621627
回答by shinercoder
I thought I would add my solution here too, in hopes to help someone. I just upgraded to Mac OS Mojave and I also upgraded to Xcode 10.2. My whole react native project broke, real bad. So then I downgraded Xcode back to 10.1. Then, I started to see this error, in said after running react-native run-ios:
我想我也会在这里添加我的解决方案,希望能帮助别人。我刚刚升级到 Mac OS Mojave,我也升级到了 Xcode 10.2。我的整个 React Native 项目都失败了,真的很糟糕。然后我将 Xcode 降级回 10.1。然后,我开始看到这个错误,在运行 react-native run-ios 后说:
Could not find iPhone X simulator
找不到 iPhone X 模拟器
the above "hack" fixed it by editing the findMatchingSimulator.js file with the updates above.
上面的“hack”通过使用上面的更新编辑 findMatchingSimulator.js 文件来修复它。
Then, react-native run-ios got farther, next error was:
然后,react-native run-ios 走得更远,下一个错误是:
:CFBundleIdentifier, does not exist
:CFBundleIdentifier,不存在
I fixed this by:
我通过以下方式解决了这个问题:
- cd node_modules/react-native/third-party/glog* TabEnter
- ./configure
- cd node_modules/react-native/第三方/glog* TabEnter
- 。/配置
Now react-native run-ios works . I hope this helps someone, this was a pain in the @ss.
现在 react-native run-ios 可以工作了。我希望这对某人有所帮助,这在@ss 中很痛苦。
回答by kaushal
if could not found simulator still persists after replacing following lines of code in runSimulator.js.
替换 runSimulator.js 中的以下代码行后,如果找不到模拟器仍然存在。
Path for runSimulator.js -> /node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
runSimulator.js 的路径 -> /node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
if (!version.startsWith('iOS') && !version.startsWith('tvOS')) { continue; }
with this one
有了这个
if ( !version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS') && !version.startsWith('com.apple.CoreSimulator.SimRuntime.tvOS') ) { continue; }
comment following lines after replacing
替换后注释以下行
if ( simulator.availability !== '(available)' && simulator.isAvailable !== 'YES' ) { continue; }
and 2nd approach after updating to XCode 11
和更新到 XCode 11 后的第二种方法
Xcode 11 xcrun returns true or false and not YES or NO for isAvailable property as before. You can check that using the following command
Xcode 11 xcrun 像以前一样为 isAvailable 属性返回 true 或 false 而不是 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
在下面的代码中将 YES 替换为 true
if ( simulator.availability !== '(available)' && simulator.isAvailable !== 'YES' ) { continue; }
like this
像这样
if ( simulator.availability !== '(available)' && simulator.isAvailable !== true ) { continue; }
回答by Evan Butler
This bug has been fixed since RN v0.58.0
, see commits here
此错误已自 RN 修复v0.58.0
,请参阅此处的提交
IIRC this bug was introduced in Xcode 10.1
IIRC 这个bug是在Xcode中引入的 10.1
Also, you can fix this by simply replacing startsWith()
with includes()
. But doing this every time you update node_modules
is less than ideal so I would recommend updating your RN version if possible.
此外,您可以通过简单地替换startsWith()
为includes()
. 但是每次更新时node_modules
都这样做不太理想,所以我建议如果可能的话更新你的 RN 版本。
回答by Tausif
You even just do something like this
你甚至只是做这样的事情
if (version.indexOf('iOS') === -1)
...
if (version.indexOf('iOS') === -1)
...