简体   繁体   English

React Native - npx react-native run-ios 在初始化项目后不起作用

[英]React Native - npx react-native run-ios doesn't work after initializing the project

After reading https://reactnative.dev/docs/environment-setup , I created a react-native project using npx react-native init *** .在阅读https://reactnative.dev/docs/environment-setup之后,我使用npx react-native init ***创建了一个 react-native 项目。

It was successful, so, I tried to run the project using npx react-native run-ios , and got the below error:它是成功的,所以,我尝试使用npx react-native run-ios运行该项目,并得到以下错误:

** BUILD FAILED **


The following build commands failed:
    CompileC /Users/loser/Library/Developer/Xcode/DerivedData/test0205-dasunahpjpavelgmslwgmvjhesxy/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/Flipper.build/Objects-normal/x86_64/FlipperRSocketResponder.o /Users/loser/Documents/projects/test0205/ios/Pods/Flipper/xplat/Flipper/FlipperRSocketResponder.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)

It's because of use_flipper in Podfile for iOS project.这是因为 iOS 项目的use_flipper中的 use_flipper。

use_flipper!

So, I was needed to indicate Flipper-Folly version with use_flipper as所以,我需要用 use_flipper 来表示Flipper-Folly版本

use_flipper!({ 'Flipper-Folly' => '2.3.0' })

It worked perfectly after that change.更改后它工作得很好。

Following Everest Climber answer跟随珠穆朗玛峰登山者的回答

  1. In Podfile under ios/ folder在 ios/ 文件夹下的 Podfile

    Change use_flipper!更改use_flipper! to use_flipper.({ 'Flipper-Folly' => '2.3.0' }) to use_flipper.({ 'Flipper-Folly' => '2.3.0' })

  2. cd ios cd ios
  3. pod install吊舱安装
  4. pod update吊舱更新
  5. cd.. && npx react-native run-ios (to run the application) cd.. && npx react-native run-ios(运行应用程序)

This worked for me.这对我有用。 Hopefully, it works for you too希望它也适合你

I could solve this issue after disabling Flipper in ios/Podfile.在 ios/Podfile 中禁用 Flipper 后,我可以解决此问题。

  1. Fix Podfile as shown in below image如下图所示修复 Podfile

在此处输入图像描述

  1. cd ios cd ios
  2. delete Pods folder and Podfile.lock删除 Pods 文件夹和 Podfile.lock
  3. pod install吊舱安装
  4. pod update吊舱更新
  5. cd.. && npx react-native run-ios cd .. && npx react-native run-ios

This seems to be an issue in react-native 0.63, try initiating the project with --version 0.62 and it should work until they fix the bug这似乎是 react-native 0.63 中的问题,尝试使用 --version 0.62 启动项目,它应该可以工作,直到他们修复错误

This issue is caused by flipper-folly pod spec updates此问题是由 Flipper-folly pod 规格更新引起的

Remove/uninstall react-native-cli, just use npx删除/卸载 react-native-cli,只需使用 npx

Try this on react-native 0.63.4 (previous stable version).在 react-native 0.63.4(以前的稳定版本)上试试这个。

Remember it doesn't work for latest 0.64.0 with XCode 12.5请记住,它不适用于带有 XCode 12.5 的最新 0.64.0

Inside ios/Podfile replace use_flipper: with:在 ios/Podfile 中将 use_flipper: 替换为:

use_flipper.({ 'Flipper-Folly' => '2.5,3'. 'Flipper' => '0.87,0'.'Flipper-RSocket' => '1.3.1' }) use_flipper.({ 'Flipper-Folly' => '2.5,3'.'Flipper' => '0.87,0'.'Flipper-RSocket' => '1.3.1' })

pod install --repo-update吊舱安装--repo-update

npx react-native run-ios npx react-native 运行-ios

if you don't need to use flipper or still getting some issues try commenting out flipper inside podfile and install pods using command如果您不需要使用鳍状肢或仍然遇到一些问题,请尝试在 podfile 中注释掉鳍状肢并使用命令安装 pod

pod install --repo-update吊舱安装--repo-update

#use_flipper!()
  #post_install do |installer|
    #flipper_post_install(installer)
  #end

Yes, Everest Climber is right.是的,珠穆朗玛峰登山者是对的。 It's broken after I updated my react-native-CLI.在我更新我的 react-native-CLI 后它坏了。 It's because of the use_flipper new version.这是因为use_flipper新版本。

Steps to fix it:修复它的步骤:

> Open Podfile for the iOS project.
> Replace `use_flipper!` with `use_flipper!({ 'Flipper-Folly' => '2.3.0' })`.
> Then you must remove both Pods directory and Podfile.lock.
> open terminal and go to iOS project directory.
> Do `pod install`.

It's worked for me perfectly.它对我来说非常有效。

React version -0.反应版本-0。 63 I am still facing the same issue while starting a new project for iOS in Mac. 63 在 Mac 中为 iOS 启动新项目时,我仍然面临同样的问题。 I have followed these steps given below but still the issue我已按照下面给出的这些步骤进行操作,但问题仍然存在

npx react-native init xxxx
cd xxxx
npx react-native run-ios
pod install

After doin this I got the following error完成此操作后,我收到以下错误

** BUILD FAILED **

The following build commands failed:
        CompileC /Users/apple/Library/Developer/Xcode/DerivedData/profirst-bbfobfkgbfqalecezvbonnkwcffv/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/Flipper.build/Objects-normal/x86_64/FlipperRSocketResponder.o /Users/apple/profirst/ios/Pods/Flipper/xplat/Flipper/FlipperRSocketResponder.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)

Later I have changed in the pod file use_flipper!后来我在pod文件中改了use_flipper! to use_flipper.({ 'Flipper-Folly' => '2.3.0' }) , but I'm still having the same issue.use_flipper.({ 'Flipper-Folly' => '2.3.0' }) ,但我仍然遇到同样的问题。

Here is a screenshot of the problem是问题的屏幕截图

  1. Replace in ios/Podfile – use_flipper!在 ios/Podfile 中替换 – use_flipper! to use_flipper.({ 'Flipper-Folly' => '2.3.0' }) to use_flipper.({ 'Flipper-Folly' => '2.3.0' })
  2. Exclude ios/Podfile.lock排除 ios/Podfile.lock
  3. pod install

If nothing works, comment it.如果没有任何效果,请发表评论。

# use_flipper!({ 'Flipper-Folly' => '2.5.1' })

The only fix worked for me唯一对我有用的解决方法

There is no need to disable flipper or juggle with its versions无需禁用鳍状肢或使用其版本进行杂耍

add this to your Podfile in post_install section将此添加到您的 Podfile 中 post_install 部分

system('cd Pods/Headers/Public; ln -s Protobuf protobuf')
system('cd Pods/OpenSSL-Universal/Frameworks/OpenSSL.xcframework/ios-arm64_arm64e_armv7_armv7s; ln -sfh OpenSSL.framework openssl.framework')
system('cd Pods/OpenSSL-Universal/Frameworks/OpenSSL.xcframework/ios-arm64_i386_x86_64-simulator; ln -sfh OpenSSL.framework openssl.framework')
system('cd Pods/OpenSSL-Universal/Frameworks/OpenSSL.xcframework/ios-arm64_x86_64-maccatalyst; ln -sfh OpenSSL.framework openssl.framework')
system('cd Pods/OpenSSL-Universal/Frameworks/OpenSSL.xcframework/macos-arm64_arm64e_x86_64; ln -sfh OpenSSL.framework openssl.framework') 

it will look like this它看起来像这样

  ...

  use_flipper!()

  post_install do |installer|
    react_native_post_install(installer)

    # check if file system is case sensitive 
    # if so then create symbolic links
    # for every openssl framework with name in lowercase
    unless File.exist? "pods"
      system('cd Pods/Headers/Public; ln -s Protobuf protobuf')
      system('cd Pods/OpenSSL-Universal/Frameworks/OpenSSL.xcframework/ios-arm64_arm64e_armv7_armv7s; ln -sfh OpenSSL.framework openssl.framework')
      system('cd Pods/OpenSSL-Universal/Frameworks/OpenSSL.xcframework/ios-arm64_i386_x86_64-simulator; ln -sfh OpenSSL.framework openssl.framework')
      system('cd Pods/OpenSSL-Universal/Frameworks/OpenSSL.xcframework/ios-arm64_x86_64-maccatalyst; ln -sfh OpenSSL.framework openssl.framework')
      system('cd Pods/OpenSSL-Universal/Frameworks/OpenSSL.xcframework/macos-arm64_arm64e_x86_64; ln -sfh OpenSSL.framework openssl.framework') 
    end

    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  end

  ...

then然后

  • remove Pods folder and Podfile.lock删除Pods文件夹和Podfile.lock

  • run pod install运行pod install

  • build your app ( npx react-native run-ios in the root folder of your app)构建您的应用程序( npx react-native run-ios在您的应用程序的根文件夹中)

Explanation解释

In my case the issue was the case sensitive file system.就我而言,问题是区分大小写的文件系统。 You can search in terminal for fatal error: 'openssl/opensslv.h' file not found or just try to build using this fix.您可以在终端中搜索fatal error: 'openssl/opensslv.h' file not found ,或者尝试使用此修复程序进行构建。

From mmemories, it's necessary to execute pod install command before !从记忆中,必须先执行pod install命令!

For me disabling flipper from Podfile works!!对我来说,从 Podfile 中禁用脚蹼!!

updated Podfile

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '10.0'

target 'ReactNativeApp' do
  config = use_native_modules!

  use_react_native!(:path => config["reactNativePath"])

  target 'ReactNativeAppTests' do
    inherit! :complete
    # Pods for testing
  end

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable these next few lines.
  # use_flipper!({ 'Flipper-Folly' => '2.3.0' })
  # post_install do |installer|
    # flipper_post_install(installer)
  # end
end

target 'ReactNativeApp-tvOS' do
  # Pods for ReactNativeApp-tvOS

  target 'ReactNativeApp-tvOSTests' do
    inherit! :search_paths
    # Pods for testing
  end
end
  • cd ios && pod install
  • cd.. && npx react-native run-ios

I tried everything here and a lot more and nothing worked!我在这里尝试了一切,而且尝试了更多,但没有任何效果!

I then:我然后:

  • deleted my node_modules (the only thing I hadn't done yet),删除了我的 node_modules (我唯一还没有做的事情),
  • deleted Pods folder and Podfile.lock,删除 Pods 文件夹和 Podfile.lock,
  • then npm install (with --legacy-peer-deps for me),然后 npm 安装(我用--legacy-peer-deps ),
  • npx pod-install (or cd ios/, pod-install) npx pod-install (或 cd ios/, pod-install)
  • npx react-native run-ios

And it finally worked.它终于奏效了。

Apparently deleting the node_modules did the trick, but do not ask me why.显然删除 node_modules 就行了,但不要问我为什么。

you can easily comment out these lines to disable flipper:您可以轻松地注释掉这些行以禁用翻转器:

  # add_flipper_pods!
  # post_install do |installer|
  #   flipper_post_install(installer)
  # end

and comment out this lines in appDelegate.m :并在appDelegate.m中注释掉这一行:

//#if DEBUG
//#import <FlipperKit/FlipperClient.h>
//#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
//#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
//#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
//#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
//#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>

//static void InitializeFlipper(UIApplication *application) {
//  FlipperClient *client = [FlipperClient sharedClient];
//  SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
//  [client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]];
//  [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
//  [client addPlugin:[FlipperKitReactPlugin new]];
//  [client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
//  [client start];
//}
//#endif

also this in the same file:这也在同一个文件中:

//  #if DEBUG
//  InitializeFlipper(application);
//  #endif
use_flipper!({ 'Flipper' => '0.145.0' })

use this in pod file.在 pod 文件中使用它。 worked for me...为我工作...

delete the podfile.lock then run,删除podfile.lock然后运行,

pod install
pod update

How to fix:怎么修:

This is caused by Flipper-Folly being broken on the latest Catalina build.这是由于 Flipper-Folly 在最新的 Catalina 版本中被破坏造成的。
Until this gets patched, your best bet is to force your cocoapods to the latest working version (2.3.0).在修复此问题之前,您最好的选择是强制您的 cocoapods 到最新的工作版本 (2.3.0)。

  1. Go to your project folder root and open the /ios directory. Go 到您的项目文件夹根目录并打开/ios目录。

     cd ios
  2. Open your Podfile and change the following block of code:打开您的Podfile并更改以下代码块:

     use_flipper!

    to

    use_flipper.({ 'Flipper-Folly' => '2.3.0' })
  3. Inside the /ios directory run the following command:/ios目录中运行以下命令:

     pod install
  4. If it worked, go back to your project root and try to run the project如果成功,go 回到您的项目根目录并尝试运行该项目

    cd.. npx react-native run-ios

    in case it didn't, check the Compatibility trouble-shooting section:如果没有,请检查兼容性故障排除部分:

Compatibility trouble-shooting兼容性故障排除

After trying to run pod install you may have gotten a similar error to this:尝试运行pod install后,您可能会遇到与此类似的错误:

[!] CocoaPods could not find compatible versions for pod "Flipper-Folly":
  In Podfile:
    Flipper-Folly (= 2.3.0)

    Flipper-RSocket (~> 1.1) was resolved to 1.3.0, which depends on
      Flipper-Folly (~> 2.5)

    FlipperKit/FBCxxFollyDynamicConvert (~> 0.54.0) was resolved to 0.54.0,
      which depends on
      Flipper-Folly (~> 2.2)

In order to solve this为了解决这个

  1. Go back to your /ios folder Go 回到你的/ios文件夹

    cd ios
  2. And remove the Podfile.lock file并删除Podfile.lock文件

    rm -rf Podfile.lock
  3. Install the pods again再次安装 pod

     pod install
  4. And run react-native并运行 react-native

     cd.. npx react-native run-ios

For me worked decision what I found in React Native repository issues on Github Xcode 12.5 troubleshooting guide (5 May 2021)对我来说,我在 Github Xcode 12.5 故障排除指南(2021 年 5 月 5 日)上的 React Native 存储库问题中找到的工作决定

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

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