Cocoapods 总是安装旧的 React (0.11.0)

Posted

技术标签:

【中文标题】Cocoapods 总是安装旧的 React (0.11.0)【英文标题】:Cocoapods always install old React (0.11.0) 【发布时间】:2018-09-06 14:52:05 【问题描述】:

我在运行 pod install Pod 时遇到问题总是降级 React Installing React 0.11.0 (was 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'

【问题讨论】:

在 pod install 之前有没有尝试使用 pod repo update 和 pod update ? 我试过了,瑜伽还是有问题:'algorithm' file not found 【参考方案1】:

只需从 pod 文件中删除 node_modules 行,然后在 xCode 中手动添加库。

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

在我的情况下,react-native-webview 出现了这个错误。

修复它:

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

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

node_modules/some_library/ios/RNCWebView.xcodeproj 拖到项目库文件中

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

【讨论】:

【参考方案2】:

如果您要将 RN 集成到现有的原生应用程序中,您会希望您的 podfile 看起来大致类似于 this。即你将通过pod 'React', :path => '../node_modules/react-native' ...指定React依赖的路径

您是否正在开发新的 RN 应用程序?如果是这样,您可能不想在您的 podfile 中包含 pod 'lottie-react-native', :path => '../node_modules/lottie-react-native',因为它可能会导致您遇到的麻烦。

相反,在运行 react-native link lottie-react-native 之前返回到您的存储库的样子。此命令可能会将 pod 'lottie-react-native', :path => '../node_modules/lottie-react-native' 行添加到您的 podfile 中。现在,您可以按照手动安装说明进行操作(我看到不存在,但您可以检查these,这将是同一件事),或者您可以执行以下操作:从node_modules/lottie-react-native 中删除lottie-react-native.podspec,然后运行react-native link lottie-react-native。依赖项不会添加到 podfile 中,而是作为静态库链接到二进制文件中。

【讨论】:

以上是关于Cocoapods 总是安装旧的 React (0.11.0)的主要内容,如果未能解决你的问题,请参考以下文章

CocoaPods 安装旧的 pod

Cocoapods “pod update” 安装旧的 pod

构建 Cordova ios 应用程序是不是总是需要 CocoaPods?

CocoaPods 安装旧版框架

React-Native:错误:无法为 iOS 项目安装 CocoaPods 依赖项,这是此模板所需的

无法通过 CocoaPods 构建 React Native 0.61.1