react-native React Native Pod文件中使用use_modular_headers!抛出模块'ReactCommon'的重复定义错误,

wecizke3  于 9个月前  发布在  React
关注(0)|答案(5)|浏览(207)

描述

Podfile 不支持 use_modular_headers! 指令,在构建时会出现错误。

重现步骤

创建一个示例的 React Native 项目 npx react-native init MyApp
向 Podfile 中添加 use_modular_headers!
执行 pod install
在 Xcode 项目中构建时出现 "Redefinition of module 'ReactCommon'" 错误。

React Native 版本

0.74.2

受影响的平台

构建 - MacOS

npx react-native info 的输出

  1. System:
  2. OS: macOS 14.4.1
  3. CPU: (12) arm64 Apple M2 Max
  4. Memory: 464.02 MB / 32.00 GB
  5. Shell:
  6. version: "5.9"
  7. path: /bin/zsh
  8. Binaries:
  9. Node:
  10. version: 18.17.0
  11. path: ~/.nvm/versions/node/v18.17.0/bin/node
  12. Yarn:
  13. version: 3.6.4
  14. path: ~/.nvm/versions/node/v18.17.0/bin/yarn
  15. npm:
  16. version: 9.6.7
  17. path: ~/.nvm/versions/node/v18.17.0/bin/npm
  18. Watchman:
  19. version: 2024.05.06.00
  20. path: /opt/homebrew/bin/watchman
  21. Managers:
  22. CocoaPods:
  23. version: 1.15.2
  24. path: /Users/jay/.gem/ruby/2.7.4/bin/pod
  25. SDKs:
  26. iOS SDK:
  27. Platforms:
  28. - DriverKit 23.2
  29. - iOS 17.2
  30. - macOS 14.2
  31. - tvOS 17.2
  32. - visionOS 1.0
  33. - watchOS 10.2
  34. Android SDK: Not Found
  35. IDEs:
  36. Android Studio: 2023.1 AI-231.9392.1.2311.11330709
  37. Xcode:
  38. version: 15.2/15C500b
  39. path: /usr/bin/xcodebuild
  40. Languages:
  41. Java:
  42. version: 11.0.18
  43. path: /usr/bin/javac
  44. Ruby:
  45. version: 2.7.4
  46. path: /Users/jay/.rubies/ruby-2.7.4/bin/ruby
  47. npmPackages:
  48. "@react-native-community/cli": Not Found
  49. react:
  50. installed: 18.2.0
  51. wanted: 18.2.0
  52. react-native:
  53. installed: 0.74.2
  54. wanted: 0.74.2
  55. react-native-macos: Not Found
  56. npmGlobalPackages:
  57. "*react-native*": Not Found
  58. Android:
  59. hermesEnabled: true
  60. newArchEnabled: false
  61. iOS:
  62. hermesEnabled: true
  63. newArchEnabled: false

堆栈跟踪或日志

  1. (Xcode error)
  2. React-RCTAppDelegate
  3. /Users/jay/tmp/rn74/MyApp/ios/Pods/Headers/Public/ReactCommon/ReactCommon.modulemap
  4. /Users/jay/tmp/rn74/MyApp/ios/Pods/Headers/Public/ReactCommon/ReactCommon.modulemap:1:8 Redefinition of module 'ReactCommon'
  5. Previously defined here

复现方法

https://github.com/jkoutavas/RN-0-74-2-example

截图和视频

此外,还有一个关于此问题的 Stack Overflow 链接:https://stackoverflow.com/questions/78540513/react-native-pod-file-use-modular-headers-throwing-redefinition-of-module-reac/78630743#78630743

5w9g7ksd

5w9g7ksd1#

尽管还有两个问题已关闭,但那里提供的解决方法不起作用,因为根据情况启用每个依赖项的模块化头文件并不总是一个可行的选择。

siv3szwd

siv3szwd2#

作为解决方法,尝试从您的Podfile中删除use_modular_headers!并仅将模块化头文件应用于特定pods。
就我的情况而言,我需要为与firebase相关的pods使用模块化头文件。

  1. pod 'FirebaseCore', :modular_headers => true
  2. pod 'Firebase', :modular_headers => true
  3. pod 'FirebaseCoreInternal', :modular_headers => true
  4. pod 'GoogleUtilities', :modular_headers => true

对我有效。

ulydmbyx

ulydmbyx3#

作为解决方法,尝试从你的Podfile中移除 use_modular_headers !,并仅将模块化头文件应用于特定的pods。
就我的情况而言,我需要为与firebase相关的pods使用模块化头文件。
这对我有效。
我们也做了同样的事情,这解决了firebase的问题,但是我们还有一个第三方包不接受:modular_headers。所以我想最好在这个问题上开一个通用的工单。

3zwjbxry

3zwjbxry4#

这个对我有效:

  1. 在我的pod文件中添加
  1. ...
  2. pod 'GoogleUtilities', :modular_headers => true
  3. pod 'FirebaseCore', :modular_headers => true
  4. # before this line 👇🏼
  5. config = use_native_modules!
  6. ...
  1. 将"@react-native-firebase/app"降级到版本: 18.6.0
kqqjbcuj

kqqjbcuj5#

我刚刚在pod文件中添加了这个

  1. ...
  2. # after this line
  3. config = use_native_modules!
  4. use_frameworks! :linkage => :static
  5. $RNFirebaseAsStaticFramework = true
  6. ...

相关问题