在 Xcode 中归档本机应用程序时出错 - 多个命令生成 'libyoga.a'

Error on archiving react native app in Xcode - Multiple commands produce 'libyoga.a'

当我尝试使用 Xcode 中的发布配置存档我的 React 本机应用程序时出现错误 - 目标 'yoga' (libyoga.a)

error: Multiple commands produce '/Users/mat/Library/Developer/Xcode/DerivedData/ListadoV1-ghytgthpajfllcakinpdoknnalbr/Build/Intermediates.noindex/ArchiveIntermediates/ListadoV1/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/libyoga.a':
1) Target 'yoga' has a command with output '/Users/mat/Library/Developer/Xcode/DerivedData/ListadoV1-ghytgthpajfllcakinpdoknnalbr/Build/Intermediates.noindex/ArchiveIntermediates/ListadoV1/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/libyoga.a'
2) Target 'yoga' has a command with output '/Users/mat/Library/Developer/Xcode/DerivedData/ListadoV1-ghytgthpajfllcakinpdoknnalbr/Build/Intermediates.noindex/ArchiveIntermediates/ListadoV1/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/libyoga.a'

如何在新构建系统中解决这个问题?

[更新 20190926:如果你升级了 cocoapods 原生的 react-native 0.60+,这种事情永远不会发生,我在下面发布的解决方法应该没有必要]


如果我可以做一些假设,你正在使用 react-native(引用了 libyoga),你正在使用 XCode 10+ 的新构建系统(不是遗留系统)并且你已经集成了 Cocoa Pods(可能使用 Firebase 或类似工具)。

如果我错了请纠正我,但那是我的设置,这就是我产生此错误的原因。

您有三个选项,按努力程度和正确性递增的顺序排列。

首先,通过将构建切换到旧构建系统[1]:

,只需 ignoring/hiding 解决问题,您就可以毫不费力地开始这一刻
1. In Xcode, go to File->Project/Workspace settings.
2. Change the build system to Legacy Build system.

其次,如果您在 Podfile 中添加变通方法片段[2],直到问题在 react-native 或 Cocoapods 的上游得到修复,您可以稍微努力一下使用新的 XCode 构建系统。我现在正在这样做并且我的项目成功归档:

 post_install do |installer|
    installer.pods_project.targets.each do |target|

      # The following is needed to ensure the "archive" step works in XCode.
      # It removes React & Yoga from the Pods project, as it is already included in the main project.
      # Without this, you'd see errors when you archive like:
      # "Multiple commands produce ... libReact.a"
      # "Multiple commands produce ... libyoga.a"

      targets_to_ignore = %w(React yoga)

      if targets_to_ignore.include? target.name
        target.remove_from_project
      end

    end
  end

(然后正如@jules-randolph 指出的那样——您必须在 iOS 文件夹中 运行 一个 pod install 才能开始使用您所做的 Podfile 更改)

第三,您可以完成将项目完全转换为 Pods 的工作,方法是删除项目中对 react-native 框架的任何遗留引用(与 Pods 配置的工作区相对) ).[3].我还没有这样做,但这是正确的做法并关闭了上游问题。

参考文献,并注意一般的父问题是有用的

[1] https://github.com/facebook/react-native/issues/20492#issuecomment-422958184

[2]https://github.com/facebook/react-native/issues/20492#issuecomment-409599358

[3]https://github.com/facebook/react-native/issues/20492#issuecomment-464343895