【问题标题】:react-native run-ios can not find any simulatorreact-native run-ios 找不到模拟器
【发布时间】:2019-06-27 16:45:28
【问题描述】:

我一直面临一个问题,即“react-native run-ios”无法启动,无论我添加到 --simulator 参数中的模拟器如何。 XCode 具有“命令行工具”的正确位置

我总是收到错误: 找不到 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 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

【问题讨论】:

    标签: ios react-native ios-simulator


    【解决方案1】:

    如果您不想使用 npm audit fix 破坏您的应用程序,请尝试 npm install --force

    【讨论】:

      【解决方案2】:

      我通过替换 YourProjectFolder/node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js 中的第 62 行来解决它

      这一行

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

      有了这个

      if (
            !simulator.isAvailable
         ) {
      

      在某些情况下,每个人都可能有一些不同的解决方案,只需通过放置 console.log() 来调试 findMatchingSimulator.js 文件,这样您就会知道为什么它没有检测到模拟器。在我的情况下,xcrun simctl list devices --json 命令不提供simulator.availabilitysimulator.isAvailable 不是字符串,而是布尔值。 我打印了模拟器列表,哪个命令通过以下行返回

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

      运行命令react-native run-ios --simulator="iPhone SE"后,我在终端中得到了输出,并根据控制台打印修复了代码。我的模拟器正在运行。

      【讨论】:

        【解决方案3】:

        这里还有额外的临时修复。我正在使用 Catalina。

        我这个文件:

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

        将第 42 行更改为:

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

        将第 52-53 行更改为:

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

        到:

        simulator.isAvailable !== true
        

        因为从命令xcrun simctl list --json devices返回的json列表,属性isAvailable是布尔值并且没有属性'availability'。

        【讨论】:

          【解决方案4】:

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

          首先启动模拟器,然后运行 ​​xcrun simctl list --json devices 并搜索带有“状态”的模拟器:“已启动”,。

          然后在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",
          

          }

          【讨论】:

            【解决方案5】:

            我尝试如下

            打开Xcode。然后Preferences -> 在选项卡中选择Components

            然后安装列表中的任何一个(或多个)可用模拟器。最好是最近的在顶部。

            它解决了问题。

            【讨论】:

            • 谢谢!像一个魅力和直观的解决方案一样工作。
            【解决方案6】:

            从终端试试这个脚本

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

            现在运行

            react-native run-ios
            

            【讨论】:

              【解决方案7】:

              更新

              在 v1.9.8 中已修复。

              更新 cli 是简单的解决方案

              npm install -g react-native-cli@latest
              

              此问题已修复,但尚未发布。 https://github.com/react-native-community/react-native-cli/pull/274

              所以可以暂时修复下面的文件。

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

              改变这一行

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

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

              当你重新安装包时不要忘记再次应用这个。

              【讨论】:

              • @n13 很高兴为您提供帮助。
              • 最新的 cli (2.0.1) 仍然不适合我。内联修复现在有效:)
              • 您的回答非常棒。
              【解决方案8】:

              做吧

              npm install

              然后它会显示警告,然后使用以下命令修复它们

              npm audit fix

              【讨论】:

              • npm audit fix 将所有依赖项更新到最新版本?这也破坏了我的应用程序
              【解决方案9】:

              我找到了一个临时修复:

              在以下文件中:

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

              ...将第 42 行更改为:

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

              【讨论】:

              • 今天将 Xcode 升级到 10.2 并遇到了这个问题。这是解决办法。谢谢!
              猜你喜欢
              • 2019-11-29
              • 2023-04-09
              • 2019-06-27
              • 2019-06-26
              • 2017-08-02
              • 1970-01-01
              • 1970-01-01
              • 2022-11-01
              • 2019-08-07
              相关资源
              最近更新 更多