【问题标题】:React Native - npx react-native run-ios doesn't work after initializing the projectReact Native - npx react-native run-ios 在初始化项目后不起作用
【发布时间】:2021-05-09 18:13:09
【问题描述】:

阅读https://reactnative.dev/docs/environment-setup后,我使用npx react-native init ***创建了一个react-native项目。

成功了,所以,我尝试使用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)

【问题讨论】:

  • 我现在遇到完全相同的问题,全新的应用程序,无法构建。我尝试使用npx react-native run-ios 和yarn ios 运行该应用程序,但没有区别。
  • 似乎是最新的 MacOs 和 xCode 试图编译 Flipper 的问题。这是一个潜在的修复:github.com/facebook/react-native/issues/…

标签: ios reactjs xcode react-native


【解决方案1】:

这是因为 iOS 项目的 Podfile 中的use_flipper。

use_flipper!

所以,我需要用 use_flipper 指明Flipper-Folly 版本

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

更改后效果很好。

【讨论】:

  • 确保删除Podfile.lock,然后在进行此更改后运行pod install。
  • 这救了我的命。我花了很多时间来解决这个问题。谢谢
【解决方案2】:

跟随珠穆朗玛峰登山者的答案

  1. 在 ios/ 文件夹下的 Podfile 中

    将 use_flipper! 更改为 use_flipper!({ 'Flipper-Folly' => '2.3.0' }) p>

  2. cd ios
  3. pod 安装
  4. pod 更新
  5. cd .. && npx react-native run-ios(运行应用程序)

这对我有用。希望它也适合你

【讨论】:

  • 这仅在将 Podfile.lock 重命名为 Podfile.lock.temp(或任何其他不同名称)后对我有效
【解决方案3】:

我可以在 ios/Podfile 中禁用 Flipper 后解决这个问题。

  1. 如下图所示修复 Podfile

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

【讨论】:

  • 太棒了。我有同样的问题,这个解决方案就像一个魅力。
【解决方案4】:

这似乎是 react-native 0.63 中的一个问题,尝试使用 --version 0.62 启动项目,它应该可以工作,直到他们修复错误

【讨论】:

  • 它帮助了我,谢谢。我使用的命令:rm -rf MyApp 删除项目目录,npx react-native init MyApp --version 0.62 使用正确版本再次创建一个空白项目。
【解决方案5】:

此问题是由 Flipper-folly pod 规格更新引起的

删除/卸载 react-native-cli,只使用 npx

在 react-native 0.63.4(以前的稳定版本)上试试这个。

请记住,它不适用于带有 XCode 12.5 的最新 0.64.0

在 ios/Podfile 中替换 use_flipper!与:

use_flipper!({ 'Flipper-Folly' => '2.5.3', 'Flipper' => '0.87.0','Flipper-RSocket' => '1.3.1' })

pod install --repo-update

npx react-native run-ios

如果您不需要使用 Flipper 或仍然遇到一些问题,请尝试在 podfile 中注释掉 Flipper 并使用命令安装 pod

pod install --repo-update

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

【讨论】:

    【解决方案6】:

    是的,珠穆朗玛峰登山者是对的。在我更新我的 react-native-CLI 后它坏了。这是因为 use_flipper 新版本。

    修复步骤:

    > 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`.
    

    它非常适合我。

    【讨论】:

      【解决方案7】:

      反应版本-0。 63 在 Mac 中为 iOS 启动一个新项目时,我仍然面临同样的问题。我已按照下面给出的这些步骤进行操作,但问题仍然存在

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

      执行此操作后出现以下错误

      ** 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)
      

      后来我在pod文件里改了 use_flipper! 到 use_flipper!({ 'Flipper-Folly' => '2.3.0' }),但我仍然遇到同样的问题。

      Here是问题截图

      【讨论】:

      • 请任何人帮助我从这一步继续前进
      • 你现在使用的 react-native 版本是什么?它在 0.63 对我来说是成功的。而且,我在 Catalina 上使用 Xcode 12.2。
      • 以上有什么解决办法吗?
      【解决方案8】:
      1. 在 ios/Podfile 中替换 - use_flipper! 到 use_flipper!({ 'Flipper-Folly' => '2.3.0' })
      2. 排除 ios/Podfile.lock
      3. pod install

      【讨论】:

        【解决方案9】:

        唯一对我有用的解决方法

        无需禁用 Flipper 或使用其版本进行调整

        将此添加到您的 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') 
        

        看起来像这样

          ...
        
          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
        
          ...
        

        然后

        • 删除Pods文件夹和Podfile.lock

        • 运行pod install

        • 构建您的应用(npx react-native run-ios 在应用的根文件夹中)

        说明

        就我而言,问题是区分大小写的文件系统。您可以在终端中搜索 fatal error: 'openssl/opensslv.h' file not found 或尝试使用此修复程序进行构建。

        【讨论】:

          【解决方案10】:

          从记忆中,必须先执行pod install命令!

          【讨论】:

            【解决方案11】:

            如果没有任何效果,请发表评论。

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

            【讨论】:

              【解决方案12】:

              对我来说,从 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

              【讨论】:

              • 禁用flipper需要添加use_frameworks或者不需要添加use_frameworks
              【解决方案13】:

              我在这里尝试了所有方法,但又尝试了很多,但没有任何效果!

              然后:

              • 删除了我的 node_modules(我唯一还没有做的事情),
              • 已删除 Pods 文件夹和 Podfile.lock,
              • 然后 npm install(我用--legacy-peer-deps),
              • npx pod-install(或 cd ios/,pod-install)
              • npx react-native run-ios

              它终于奏效了。

              显然删除 node_modules 是成功的,但不要问我为什么。

              【讨论】:

                【解决方案14】:

                您可以轻松地注释掉这些行以禁用翻转器:

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

                并在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
                

                也在同一个文件中:

                //  #if DEBUG
                //  InitializeFlipper(application);
                //  #endif
                

                【讨论】:

                  【解决方案15】:

                  如何解决:

                  这是由于 Flipper-Folly 在最新的 Catalina 版本中被破坏造成的。
                  在修复此问题之前,您最好的办法是强制您的 cocoapods 使用最新的工作版本 (2.3.0)。

                  1. 转到您的项目文件夹根目录并打开/ios 目录。

                    cd ios
                    
                  2. 打开您的Podfile 并更改以下代码块:

                    use_flipper!
                    

                    到

                    use_flipper!({ 'Flipper-Folly' => '2.3.0' })
                    
                  3. 在/ios 目录中运行以下命令:

                    pod install
                    
                  4. 如果成功,请返回您的项目根目录并尝试运行该项目

                    cd ..
                    npx react-native run-ios
                    

                    如果没有,请检查兼容性故障排除部分:

                  兼容性问题排查

                  在尝试运行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)
                  

                  为了解决这个问题

                  1. 返回您的/ios 文件夹

                    cd ios
                    
                  2. 并删除Podfile.lock 文件

                    rm -rf Podfile.lock
                    
                  3. 再次安装 pod

                    pod install
                    
                  4. 然后运行 ​​react-native

                    cd ..
                    npx react-native run-ios
                    

                  【讨论】:

                    猜你喜欢
                    • 2021-07-21
                    • 1970-01-01
                    • 1970-01-01
                    • 2021-06-23
                    • 2020-04-02
                    • 2022-07-30
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    相关资源
                    最近更新 更多