Javascript 从终端 (iOS) 运行 React Native App 时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39778607/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 22:54:07  来源:igfitidea点击:

Error Running React Native App From Terminal (iOS)

javascriptiosreactjsreact-nativeios-simulator

提问by JacobSiegel

I am following the tutorial on the official React Native website.

我正在关注官方 React Native 网站上的教程。

Using the following to build my project:

使用以下内容来构建我的项目:

react-native run-ios

I get the error:

我收到错误:

Found Xcode project TestProject.xcodeproj
xcrun: error: unable to find utility "instruments", not a developer   
tool or in PATH

Command failed: xcrun instruments -s
xcrun: error: unable to find utility "instruments", not a developer 
tool or in PATH

Although, when I run the app from the .xcodeproj, everything works fine.

虽然,当我从 .xcodeproj 运行应用程序时,一切正常。

Any suggestions?

有什么建议?

回答by leo7r

Check out this link (Running react-native run-ios occurs an error?). It appears to be a problem with the location of Command line tools.

查看此链接(运行 react-native run-ios 出现错误?)。似乎是位置的问题Command line tools

In Xcode, select Xcode menu, then Preferences, then Locations tab. Select your Xcode version from the dropdown and exit Xcode.

在 Xcode 中,依次选择 Xcode 菜单、首选项和位置选项卡。从下拉列表中选择您的 Xcode 版本并退出 Xcode。

XCode location tab

XCode 位置选项卡

回答by odlp

You may need to install or set the location of the Xcode Command Line Tools.

您可能需要安装或设置Xcode Command Line Tools的位置。

Via command line

通过命令行

If you have Xcode downloaded you can run the following to set the path:

如果您下载了 Xcode,则可以运行以下命令来设置路径:

sudo xcode-select -s /Applications/Xcode.app

If the command line tools haven't been installed yet, you may need to run this first:

如果尚未安装命令行工具,您可能需要先运行以下命令:

xcode-select --install

You may need to accept the Xcode license before installing command line tools:

在安装命令行工具之前,您可能需要接受 Xcode 许可证:

sudo xcodebuild -license accept 


Via Xcode

通过 Xcode

Or adjust the Command Line Toolssetting via Xcode (Xcode > Preferences > Locations):

或者Command Line Tools通过 Xcode ( Xcode > Preferences > Locations)调整设置:

Xcode preferences - Locations tab

Xcode 首选项 - 位置选项卡

回答by Alireza

By default, after installing Xcodecommand-line not selected, so open Xcodeand go to Preferences >> Locationsand set Command Line Tools...

默认情况下,安装Xcode后没有选择命令行,所以打开Xcode并转到Preferences >> Locations并设置Command Line Tools...

This worked for me in MAC High Sierra, Xcode Version 9.3:

这在MAC High SierraXcode 版本 9.3 中对我有用

Xcode Preferences

Xcode 首选项

Press ito open iOS emulator...

按下i打开iOS模拟器...

Press a to open Android device or emulator, or i to open iOS emulator.

按 a 打开 Android 设备或模拟器,或按 i 打开 iOS 模拟器。

And You can see a cool new iPhone simulator like below image:

你可以看到一个很酷的新 iPhone 模拟器,如下图所示:

React Native prints, I'm Alireza Dezfoolian, a Front End Developer!

React Native 打印,我是前端开发人员 Alireza Dezfoolian!

回答by Heisenberg

In my case the problem was that Xcode was not installed.

就我而言,问题是未安装 Xcode。

回答by Mario Tacke

I had to accept the XCode license after my first install before I could run it. You can run the following to get the license prompt via command line. You have to type agreeand confirm as well.

第一次安装后,我必须接受 XCode 许可证才能运行它。您可以运行以下命令以通过命令行获取许可证提示。您还必须输入agree并确认。

sudo xcodebuild -license

回答by Lovekush Vishwakarma

Problem is your Xcode version is not set on Command Line Tools, to solve this problem open Xcode>Menu>preferences> location> here for Command Line tools select your Xcode version, that's it. enter image description here

问题是您的 Xcode 版本未在命令行工具上设置,要解决此问题,请打开 Xcode>Menu>preferences>location> 此处为命令行工具选择您的 Xcode 版本,就是这样。 在此处输入图片说明

回答by Zachary Melancon

For those like me who come to this page with this problem after updating Xcode but don't have an issue with the location setting, restarting my computer did the trick.

对于像我这样在更新 Xcode 后遇到此问题但在位置设置方面没有问题的人来说,重新启动我的计算机就成功了。

回答by Bin

For me, it turns out that there was an iOS system update pending asking to restart the computer. Restart and let the update finish solved my problem.

对我来说,事实证明有一个 iOS 系统更新未决,要求重新启动计算机。重新启动并让更新完成解决了我的问题。

回答by python1981

In my case the SDKROOT environment variable was wrong, which referred to an old version of iPhoneOSxx.x.sdk. (Perhaps this would have automatically resolved itself after a reboot?)

在我的情况下,SDKROOT 环境变量是错误的,它指的是旧版本的 iPhoneOSxx.x.sdk。(也许这会在重新启动后自动解决?)

You can check by running echo $SDKROOTand verifying that it's a valid path.

您可以通过运行echo $SDKROOT并验证它是否是有效路径来进行检查。

I fixed it by updating in .bash_profile:

我通过在 .bash_profile 中更新来修复它:

export SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.2.sdk

回答by user11279823

None of these solutions worked for me. These two similar problems offer temporary solutions that worked, it seems the simulator process isn't being shutdown correctly:

这些解决方案都不适合我。这两个类似的问题提供了有效的临时解决方案,似乎模拟器进程没有正确关闭:

Killing Simulator Processes

杀死模拟器进程

From https://stackoverflow.com/a/52533391/11279823

来自https://stackoverflow.com/a/52533391/11279823

  1. Quit the simulator & Xcode.
  2. Opened Activity monitor, selected cpuoption and search for sim, killing all the process shown as result.
  3. Then fired up the terminal and run sudo xcrun simctl erase all. It will delete all content of all simulators. By content if you logged in somewhere password will be gone, all developer apps installed in that simulator will be gone.
  1. 退出模拟器和 Xcode。
  2. 打开Activity monitor,选择cpu选项并搜索sim,杀死所有显示的进程结果。
  3. 然后启动终端并运行sudo xcrun simctl erase all。它将删除所有模拟器的所有内容。根据内容,如果您在某个地方登录密码将消失,则安装在该模拟器中的所有开发人员应用程序都将消失。

Opening Simulator before starting the package

开始打包前打开模拟器

From https://stackoverflow.com/a/55374768/11279823

来自https://stackoverflow.com/a/55374768/11279823

open -a Simulator; npm start

open -a Simulator; npm start

Hopefully a permanent solution is found.

希望找到永久解决方案。