我在运行 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
进入项目库文件
在build phases link binary with libraries
中添加库依赖
关于ios - Cocoapods 总是安装旧的 React (0.11.0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52206865/