ios - Cocoapods 总是安装旧的 React (0.11.0)

标签 ios react-native cocoapods

我在运行 pod install 时遇到问题 Pod 总是降级 React 正在安装 React 0.11.0(原为 0.55.4)

我的 pod 文件:

# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
platform :ios, '9.0'
project 'BunteMobile.xcodeproj'
target 'BunteMobile' do
  # Comment this line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for BunteMobile
  pod 'Adjust', '~> 4.8.3'
  pod 'Google-Mobile-Ads-SDK'
  pod 'GoogleAds-IMA-iOS-SDK', '~> 3.7'
  pod 'Fabric', '~> 1.7.0'
  pod 'Crashlytics', '~>  3.9'

  pod 'lottie-ios', :path => '../node_modules/lottie-ios'

  pod 'lottie-react-native', :path => '../node_modules/lottie-react-native'

  target 'BunteMobileTests' do
    inherit! :search_paths
    # Pods for testing
  end

end

当我从 node_modules 定义 react 文件夹时,我读到了一些解决方案,但这个解决方案对我也不起作用。

我把这个放到podfile中:

pod 'yoga', path: './node_modules/react-native/ReactCommon/yoga'
pod 'React', :path => '../node_modules/react-native'

但还是不行。降级消失了,但是当我尝试构建它时,我遇到了这个错误:

/node_modules/react-native/React/Base/RCTConvert.h:17:9: could not build module 'yoga'

我尝试了与官方 RN 文档(https://facebook.github.io/react-native/docs/integration-with-existing-apps.html)相同的配置文件,但仍然出现相同的错误。


解决方案

我将其添加到我的 podfile 中:

# Pods for React-Native start
  pod 'React', :path => '../node_modules/react-native'
  pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'

(2019 年更新)解决方案 2(react-native 0.61+):将此添加到 pod 文件

  # Pods for React-Native start
  pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
  pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
  pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
  pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
  pod 'React', :path => '../node_modules/react-native/'
  pod 'React-Core', :path => '../node_modules/react-native/'
  pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
  pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
  pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
  pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
  pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
  pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
  pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
  pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
  pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
  pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
  pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
  pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'

  pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
  pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
  pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
  pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
  pod 'ReactCommon/jscallinvoker', :path => "../node_modules/react-native/ReactCommon"
  pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
  pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'

最佳答案

只需删除 node_modules pod 文件中的行并在 xCode 中手动添加库。

我观察到当你运行 react-native link <someLibrary>有时 RN 会自动将该库添加为 pod 依赖项。

在我的例子中,这个错误出现在 react-native-webview 上。

修复它:

我刚刚删除了 node_modules/react-native-webview pod 文件中的行 然后

在 xCode 中的其他库附近添加了该库

拖动node_modules/some_library/ios/RNCWebView.xcodeproj 进入项目库文件

enter image description here

build phases link binary with libraries中添加库依赖

enter image description here

关于ios - Cocoapods 总是安装旧的 React (0.11.0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52206865/

相关文章:

ios - NSMutableArray 在多个索引处初始化

ios - NS_ENUM 作为协议(protocol)中的属性

ios - 如何将 CocoaPods 依赖项与 Cordova 插件捆绑在一起?

ios - Swift框架与Cocoapods——整合静态库

swift - 使用 Swift Package Manager、Cocoa Pods 或其他工具将最小 GRDB 添加到 Xcode 项目

ios - 是否可以在类/结构实例方法中调用 GameScene 函数?

ios - 应用程序更新期间的核心数据同步

react-native - React-native 的 Realm 。重置数据库

android - react native 选择器样式自定义字体

android - react-native 在构建期间获取发布构建包名称/包 id?