更新到 xcode 11.0 后无法构建 React Native 项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/58054691/
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
Unable to build react native project after updating to xcode 11.0
提问by Ganesh Krishna
I have a react native project running on react native version 0.59.8 , and xcode version 10.3. Somehow my xcode got updated to version 11.0 and after that i am unable to build the project using react-native run-ios
command.
我有一个在本机版本 0.59.8 和 xcode 版本 10.3 上运行的本机项目。不知何故,我的 xcode 更新到了 11.0 版,之后我无法使用react-native run-ios
命令构建项目。
I have tried cleaning up the build and building again. But that doesn't help.
我尝试再次清理构建和构建。但这无济于事。
I am getting the following error:
我收到以下错误:
CoreData: annotation: Failed to load optimized model at path '/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/Frameworks/InstrumentsPackaging.framework/Versions/A/Resources/XRPackageModel.momd/XRPackageModel 9.0.omo'
error Could not find iPhone X simulator.
How to fix this issue?
如何解决这个问题?
回答by Alex Bin Zhao
Not sure about the first error, but I have same problem for second error error Could not find iPhone X simulator
after upgrade to XCode 11
不确定第一个错误,但我error Could not find iPhone X simulator
在升级到 XCode 11 后遇到第二个错误同样的问题
Basically I changed the line 53 in the react native project /node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
, from simulator.isAvailable !== 'YES'
to simulator.isAvailable !== true
.
基本上我的反应本地项目改了行53 /node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
,从simulator.isAvailable !== 'YES'
到simulator.isAvailable !== true
。
The root cause is new XCode 11 changed the simulator metadata format, and react native findMatchingSimulator method is strongly coupled to the previous format.
根本原因是新的 XCode 11 更改了模拟器元数据格式,并且 react native findMatchingSimulator 方法与以前的格式强耦合。
回答by Ganesh Krishna
I was able to fix the "Could not find iPhone X simulator" error.
我能够修复“找不到 iPhone X 模拟器”错误。
These are the steps to fix the above error:
这些是修复上述错误的步骤:
Run the command find . -iname findMatchingSimulator.js
to locate findMatchingSimulator.js
file.
运行命令find . -iname findMatchingSimulator.js
定位findMatchingSimulator.js
文件。
In this file, Change the code from
在此文件中,将代码从
if (simulator.availability !== '(available)' && simulator.isAvailable !== 'YES') {
continue;
}
to
到
if (simulator.availability !== '(available)' && simulator.isAvailable !== true) {
continue;
}
By doing this simulator error is resolved. But Still the other error
通过这样做,模拟器错误得到解决。但仍然是另一个错误
CoreData: annotation: Failed to load optimized model at path '/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/Frameworks/InstrumentsPackaging.framework/Versions/A/Resources/XRPackageModel.momd/XRPackageModel 9.0.omo'
exists, which makes the build to fail. If I install xcode 10.3 and run the command react-native run-ios
, it still works.
Hope the issue is clear. Any fixes for this issue which occurs in xcode 11?
存在,这会使构建失败。如果我安装 xcode 10.3 并运行命令react-native run-ios
,它仍然有效。希望问题很清楚。对 xcode 11 中发生的这个问题有什么修复吗?
回答by Rodolphe Lemasquerier
Two things:
两件事情:
With Xcode 11, make sure you're using react-native-community/cli version 1.9.8 minimum, as it integrates the fix for Xcode 11 simulators new metadata format:
https://github.com/react-native-community/cli/releases/tag/v1.9.8
Also, the iPhone X simulator is no longer available at least on my end. You can use an iPhone 11 instead :
对于 Xcode 11,请确保您使用的是 react-native-community/cli version 1.9.8 minimum,因为它集成了针对 Xcode 11 模拟器新元数据格式的修复:
https://github.com/react-native-community/cli/releases/tag/v1.9.8
此外,至少在我这边,iPhone X 模拟器不再可用。您可以改用 iPhone 11:
react-native run-ios --simulator='iPhone 11'
回答by NYSamnang
In my case:
就我而言:
react: 16.8.3
react-native: 0.59.9
Xcode: 11.0
- Add iPhone X simulator: Open Xcode => Window => Devices and Simulators => Simulators => Press Plus button at the bottom
- Install latest version of cocoapods:
sudo gem install cocoapods
- Re-Install cocoapods in project: Open project folder => ios => delete
Podfile.lock
,Pods
folder,build
folder =>cd ios && pod install
react-native run-ios
Done!
- 添加 iPhone X 模拟器:打开 Xcode => 窗口 => 设备和模拟器 => 模拟器 => 按底部的加号按钮
- 安装最新版本的 cocoapods:
sudo gem install cocoapods
- 在项目中重新安装 cocoapods:打开项目文件夹 => ios => 删除
Podfile.lock
,Pods
文件夹,build
文件夹 =>cd ios && pod install
react-native run-ios
完毕!
回答by Himanshu Sharma
After upgrading my XCode to version 11, in XCode simulators list it only shows ios 13 simulators as available, so we need to add previous version simulators, to do so, in XCode go to preferences -> Components -> and download and install a previous version ios simulator (ios 11.0 in my case), after doing so it must show other simulators in available simulator list. Clear all cache and re-run the react-native run-ios command and it should work now.
将我的 XCode 升级到版本 11 后,在 XCode 模拟器列表中它只显示可用的 ios 13 模拟器,因此我们需要添加以前版本的模拟器,为此,在 XCode 中转到首选项 -> 组件 -> 并下载并安装以前的模拟器ios模拟器版本(在我的例子中是ios 11.0),这样做之后它必须在可用模拟器列表中显示其他模拟器。清除所有缓存并重新运行 react-native run-ios 命令,它现在应该可以工作了。
回答by Amar Zanashir
Try run specifying simulator version.
尝试运行指定模拟器版本。
react-native run-ios --simulator="iPhone 11 Pro Max"
回答by Metehan Senol
I upgraded "react-native"
to "^0.61.1"
and it worked for me
我升级"react-native"
到"^0.61.1"
它对我有用
回答by Roosma
Run can run xcrun simctl list devices
in a terminal to make sure you have the iPhone X simulator installed. If you can't see it in the list you need to add it to Xcode through Window -> Devices and Simulators -> Simulators
(click the + in the bottom left)
Run 可以xcrun simctl list devices
在终端中运行以确保您安装了 iPhone X 模拟器。如果在列表中看不到它,则需要通过Window -> Devices and Simulators -> Simulators
(单击左下角的 +)将其添加到 Xcode
回答by Chris Cornelius
I was having this same issue, and even went back to xCode 10.3....and still had the same issue. Then I came across this https://github.com/react-native-community/cli/pull/414. Sounded to me like maybe they had fixed the issue and that I was running with an old version of the CLI. Proceeded to delete the entry in my lock file and run npm install. Working now. CLI is up to 1.11.2 https://github.com/react-native-community/cli
我遇到了同样的问题,甚至回到了 xCode 10.3 ......仍然有同样的问题。然后我遇到了这个https://github.com/react-native-community/cli/pull/414。在我看来,他们可能已经解决了这个问题,而且我正在使用旧版本的 CLI 运行。继续删除我的锁定文件中的条目并运行 npm install。现在工作。CLI 最高 1.11.2 https://github.com/react-native-community/cli