在获得的项目上安装 Cocoapods 时遇到问题

Posted

技术标签:

【中文标题】在获得的项目上安装 Cocoapods 时遇到问题【英文标题】:Having trouble installing Cocoapods on an obtained project 【发布时间】:2020-10-16 17:15:07 【问题描述】:

我从一位同事那里收到了一个项目,该项目没有包含在文件中的框架,我认为这不会是一个大问题,因为我过去使用过 Cocoapods 却没有遇到任何问题,但是我真的很难安装这些。下面是我的 Podfile 以及我在尝试执行 pod install 时收到的错误。有人可以告诉我出了什么问题,并告诉我如何解决它。

错误日志:

Analyzing dependencies
Fetching podspec for `DoubleConversion` from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`
Fetching podspec for `Folly` from `../node_modules/react-native/third-party-podspecs/Folly.podspec`
Fetching podspec for `glog` from `../node_modules/react-native/third-party-podspecs/glog.podspec`
[!] CocoaPods could not find compatible versions for pod "React/RCTVibration":
  In Podfile:
    React/RCTVibration (from `../node_modules/react-native`)

None of your spec sources contain a spec satisfying the dependency: `React/RCTVibration (from `../node_modules/react-native`)`.

You have either:
 * out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
 * mistyped the name or version.
 * not added the source repo that hosts the Podspec to your Podfile.

[!] Automatically assigning platform `ios` with version `9.0` on target `bestride` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`

Podfile:

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

project 'bestride.xcodeproj'

target 'bestride' do
    rn_path = '../node_modules/react-native'
    rn_maps_path = '../node_modules/react-native-maps'
  
    # See http://facebook.github.io/react-native/docs/integration-with-existing-apps.html#configuring-cocoapods-dependencies
    pod 'yoga', path: "#rn_path/ReactCommon/yoga/yoga.podspec"
    pod 'React', path: rn_path, subspecs: [
      'Core',
      'CxxBridge',
      'DevSupport',
      'RCTActionSheet',
      'RCTAnimation',
      'RCTGeolocation',
      'RCTImage',
      'RCTLinkingIOS',
      'RCTNetwork',
      'RCTSettings',
      'RCTText',
      'RCTVibration',
      'RCTWebSocket',
    ]
  
    # React Native third party dependencies podspecs
    pod 'DoubleConversion', :podspec => "#rn_path/third-party-podspecs/DoubleConversion.podspec"
    pod 'glog', :podspec => "#rn_path/third-party-podspecs/glog.podspec"
    # If you are using React Native <0.54, you will get the following error:
    # "The name of the given podspec `GLog` doesn't match the expected one `glog`"
    # Use the following line instead:
    #pod 'GLog', :podspec => "#rn_path/third-party-podspecs/GLog.podspec"
    pod 'Folly', :podspec => "#rn_path/third-party-podspecs/Folly.podspec"
  
    # react-native-maps dependencies
    pod 'react-native-maps', path: rn_maps_path
    pod 'react-native-google-maps', path: rn_maps_path  # Uncomment this line if you want to support GoogleMaps on iOS
    pod 'GoogleMaps'  # Uncomment this line if you want to support GoogleMaps on iOS
    pod 'Google-Maps-iOS-Utils' # Uncomment this line if you want to support GoogleMaps on iOS
    pod 'react-native-fbsdk', :path => '../node_modules/react-native-fbsdk'
    pod 'FBSDKCoreKit', '~>4.42.0'
    pod 'FBSDKLoginKit', '~>4.42.0'
    pod 'FBSDKShareKit', '~>4.42.0'
    pod 'GoogleSignIn'
    pod 'RNGoogleSignin', :path => '../node_modules/react-native-google-signin'

    pod 'RNImageCropPicker', :path => '../node_modules/react-native-image-crop-picker'

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

    pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-community/async-storage'

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

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

    pod 'react-native-splash-screen', :path => '../node_modules/react-native-splash-screen'
    pod 'react-native-date-picker', :path => '../node_modules/react-native-date-picker'
    pod 'RNDeviceInfo', :path => '../node_modules/react-native-device-info'

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

  end
  
  post_install do |installer|
    installer.pods_project.targets.each do |target|
      if target.name == 'react-native-google-maps'
        target.build_configurations.each do |config|
          config.build_settings['CLANG_ENABLE_MODULES'] = 'No'
        end
      end
      if target.name == "React"
        target.remove_from_project
      end
    end
  end

【问题讨论】:

请检查我对 RN 0.64.0 ***.com/a/66998345/9673374的回答 【参考方案1】:

尝试这样做

pod deintegrate
pod install
pod update

【讨论】:

【参考方案2】:

一个好的起点可以是运行pod deintegrate 命令。

过去,当我遇到 CocoaPods 问题时,从头开始重新启动配置解决了我的错误。

您可以尝试以下命令从头开始。确保将您的 Pod 文件搁置在其他地方,以便您可以参考要安装的框架。

$ sudo gem install cocoapods-deintegrate cocoapods-clean
$ pod deintegrate
$ pod cache clean --all
$ rm Podfile

然后,跟进并执行:

pod install
pod update

另外,由于您使用的是 React,您的节点安装可能会出现问题,在这种情况下,我建议您参考 this post

注意:可能发生的情况是你的框架已经过时了,它们可能被缓存在你的系统中,从而链接到旧的不匹配引用。

【讨论】:

以上是关于在获得的项目上安装 Cocoapods 时遇到问题的主要内容,如果未能解决你的问题,请参考以下文章

将 GoogleCast SDK 与 Cocoapods 集成

cocoapods 安装代码在库上崩溃后

cocoapods 安装第三方库,遇到的问题整理

iOS--安装Cocoapods遇到的问题和解决方法

cocoapods 不能用了 怎么办

cocoapods的安装,使用,卸载,以及你可能会遇到的坑..