简体   繁体   English

react-native run-ios 找不到任何模拟器

[英]react-native run-ios can not find any simulator

I have been facing an issue where 'react-native run-ios' can not start, regardless of the simulator I add to the --simulator argument.我一直面临一个问题,即无论我添加到 --simulator 参数中的模拟器如何,“react-native run-ios”都无法启动。 XCode has the correct location for the 'command line tools' XCode 具有“命令行工具”的正确位置

I am always getting the error: Could not find iPhone X simulator我总是收到错误:找不到 iPhone X 模拟器

Error: Could not find iPhone X simulator
    at resolve (/Users/eric/.../swim/node_modules/react-native/local-cli/runIOS/runIOS.js:149:13)
    at new Promise (<anonymous>)
    at runOnSimulator (/Users/eric/.../swim/node_modules/react-native/local-cli/runIOS/runIOS.js:134:10)
    at Object.runIOS [as func] (/Users/eric/.../swim/node_modules/react-native/local-cli/runIOS/runIOS.js:106:12)
    at Promise.resolve.then (/Users/eric/.../swim/node_modules/react-native/local-cli/cliEntry.js:117:22)

react-native info反应本机信息

>   React Native Environment Info:
>     System:
>       OS: macOS 10.14.2
>       CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
>       Memory: 6.76 GB / 32.00 GB
>       Shell: 3.2.57 - /bin/bash
>     Binaries:
>       Node: 10.15.0 - /usr/local/bin/node
>       Yarn: 1.13.0 - /usr/local/bin/yarn
>       npm: 6.4.1 - /usr/local/bin/npm
>     SDKs:
>       iOS SDK:
>         Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
>     IDEs:
>       Android Studio: 3.1 AI-173.4819257
>       Xcode: 10.1/10B61 - /usr/bin/xcodebuild
>     npmPackages:
>       react: 16.6.3 => 16.6.3 
>       react-native: 0.57.8 => 0.57.8 
>     npmGlobalPackages:
>       create-react-native-app: 1.0.0
>       react-native-cli: 2.0.1
>       react-native-git-upgrade: 0.2.7

Update更新

It is fixed in v1.9.8.它在 v1.9.8 中得到修复。

Update cli is the easy solution更新 cli 是最简单的解决方案

npm install -g react-native-cli@latest

This issue is fixed but not released yet.此问题已修复但尚未发布。 https://github.com/react-native-community/react-native-cli/pull/274 https://github.com/react-native-community/react-native-cli/pull/274

So it can be solved temporarily to fix the file below.所以可以暂时解决修复下面的文件。

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

Change this line改变这一行

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

to

if (!version.includes('iOS') && !version.includes('tvOS')) {

Do not forget apply this again when you reinstall packages.重新安装软件包时不要忘记再次应用它。

I've found a temporary fix:我找到了一个临时修复:

In the following file:在以下文件中:

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

...change line 42 to: ...将第 42 行更改为:

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

Try this script from Terminal从终端试试这个脚本

sed -i '' 's/startsWith/includes/g' node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js sed -i '' 's/startsWith/includes/g' node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js

Now run现在运行

react-native run-ios

I tried like below我试过如下

Open Xcode .打开Xcode Then Preferences -> Select Components in Tabs.然后Preferences - >在选项卡中选择Components

Then install any one(or more) of the available simulators on the list.然后安装列表中的任何一个(或多个)可用模拟器。 Preferably the recent one at the top.最好是最近的一个在顶部。

It solves the problem.它解决了这个问题。

Just do做就是了

npm install

Then it will show warnings, then fix them by using following command然后它会显示警告,然后使用以下命令修复它们

npm audit fix

Here is additional temporary fix too.这里也是额外的临时修复。 I am using Catalina.我正在使用卡特琳​​娜。

I this file:我这个文件:

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

Change line 42 to:将第 42 行更改为:

if (!version.includes('iOS') && !version.includes('tvOS')) {

Change line 52-53 from:将第 52-53 行从:

simulator.availability !== '(available)' &&
simulator.isAvailable !== 'YES'

to:到:

simulator.isAvailable !== true

because the returned json list from command xcrun simctl list --json devices , the property isAvailable is boolean and didn't have property 'availability'.因为从命令xcrun simctl list --json devices返回的 json 列表,属性 isAvailable 是布尔值并且没有属性“可用性”。

Just modify the findMatchingSimulator.js in node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js.只需修改 node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js 中的 findMatchingSimulator.js 即可。

First boot a Simulator then run xcrun simctl list --json devices and search the one with "state" : "Booted",.首先启动一个模拟器,然后运行 ​​xcrun simctl list --json devices 并搜索带有“state”的那个:“Booted”,。

Then add at the top in the findMatchingSimulator function:然后在 findMatchingSimulator 函数的顶部添加:

return {
udid: <uuid from booted device>, // 'BFA2D7D0-AD49-472F-8279-585DDBBF9151'
name: <Name of the booted simulator>, //"iPhone X"
booted: true,
version: "com.apple.CoreSimulator.SimRuntime.iOS-13-1",

} }

I solved it by replacing line number 62 in YourProjectFolder/node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js我通过替换YourProjectFolder/node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js第 62 行来解决它

This line这条线

if (
        simulator.availability !== '(available)' &&
        simulator.isAvailable !== 'YES'
      ) {

With this one有了这个

if (
      !simulator.isAvailable
   ) {

In some case there may be some different solutions for everyone just debug findMatchingSimulator.js file by putting console.log() so you'll know why it is not detecting simulator.在某些情况下,每个人可能会有一些不同的解决方案,只需通过放置 console.log() 来调试 findMatchingSimulator.js 文件,这样您就会知道为什么它没有检测到模拟器。 In my case the xcrun simctl list devices --json command not providing simulator.availability and simulator.isAvailable is not string it's bool.在我的情况下, xcrun simctl list devices --json命令不提供simulator.availability xcrun simctl list devices --jsonsimulator.isAvailable xcrun simctl list devices --json不是字符串,它是布尔值。 I printed the simulator list which command is returning through the following line我打印了模拟器列表,哪个命令通过以下行返回

  console.log(JSON.stringify(simulator.simulatorName));
  console.log(simulator.isAvailable);
  console.log('-------------------------------------------------------------');

The after running command react-native run-ios --simulator="iPhone SE" I got output in the terminal and fixed code according to console print.运行后的命令react-native run-ios --simulator="iPhone SE"我在终端中得到了输出,并根据控制台打印得到了固定代码。 And my simulator was running.我的模拟器正在运行。

如果您不想使用 npm 审计修复程序破坏您的应用程序,请尝试 npm install --force

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM