本文介绍了如何创建具有在Specs之外存在的依赖项的CocoaPods podspec?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一个CocoaPods / Specs中已经存在的库的公共分支。在Podfile中,我可以通过以下方式引用此分叉的pod:

I have a public fork of a library that already exists in CocoaPods/Specs. In a Podfile, I can reference this forked pod by doing this:

pod 'CoolLibrary', :git => '[email protected]:myname/CoolLibrary-Forked.git', :commit => 'abcdef1234567890abcdef1234567890'

我尝试将其放入我的 MyLibrary.podspec

s.dependency 'CoolLibrary', :git => '[email protected]:myname/CoolLibrary-Forked.git', :commit => 'abcdef1234567890abcdef1234567890'

但是收到以下错误消息:

But get the following error message:

-> MyLibrary.podspec
 - ERROR | The specification defined in `MyLibrary.podspec` could not be loaded.


[!] Invalid `MyLibrary.podspec` file: [!] Unsupported version requirements. Updating CocoaPods might fix the issue.

是否可以通过这种方式在.podspec中指定依赖项(例如,对于具有

Is it possible to specify a dependency in a .podspec in this way (i.e. for a pod that has a podspec, but which isn't in CocoaPods/Specs)?

推荐答案

这是Podspec不允许的,因为这样做会允许使其他podspec几乎无法定义它们依赖的包和/或由于意外的API差异而可能破坏其他包。

This is not allowed from podspecs, because allowing so would make it next to impossible for other podspecs to define what package they depend on and/or other packages could break because of unexpected API differences.

例如,考虑两个取决于AFNetworking,但是一个指定外部源位置(位置A),而另一个仅指定最低版本要求(位置B):

For instance, consider two pods that depend on AFNetworking, but one specifies an external source location (Pod A) while the other only specifies a minimum version requirement (Pod B):


  • Pod A: s.dependency'AFNetworking',:git => ‘https:// arbitrary / location’

  • Pod B: s.dependency‘AFNetworking’,’> 2'

  • Pod A: s.dependency 'AFNetworking', :git => 'https://arbitrary/location'
  • Pod B: s.dependency 'AFNetworking', '> 2'

现在有两个潜在的问题:

Now there are a couple of potential problems:


  1. 在这一点上,直到我们下载它之前,我们都不知道'Pod A'存储库中的版本是什么,如果在AFNetworking上存在各种常见的依赖关系,这将浪费大量时间(例如 Pod B)。

  2. 但更糟糕的是,如果 Pod A 符合与其他Pod的依赖版本要求匹配(例如 Pod B),但AFNetworking代码实际上是来自分叉的源位置,它更改了 Pod B所依赖的一些基本API。

  1. At this point we have no idea what version is in the ‘Pod A’ repo until we download it, which is a massive waste of time in case the various common dependencies on AFNetworking (e.g. ’Pod B’) can’t be satisfied.
  2. But what’s even worse is if ‘Pod A’ does match the dependency version requirement of other pods (e.g. ‘Pod B’), but the AFNetworking code is actually from a forked source location and it changes some essential API that ’Pod B’ depends on. This will silently break the promise that CocoaPods tries to make.

我希望这可以弄清楚为什么我们不能为Podspecs引入一种方法默默地违反版本承诺。但是,您可以从您的Podfile中 覆盖任何Pod的源位置,因为由最终用户(应用开发者)控制,并且不应出现任何意外 strong>破损。

I hope this makes it clear why we cannot introduce a way for podspecs to silently break the version promises. However, from your Podfile you are allowed to override any pod’s source location, because it is the end-user (the app developer) who is in control and there should not be any unexpected breakage.

这篇关于如何创建具有在Specs之外存在的依赖项的CocoaPods podspec?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 22:58