简体   繁体   English

将带有源的 Pod 依赖项添加到 .podspec

[英]Add Pod dependency with source to .podspec

I am trying to add the following dependency to my Podspec我正在尝试将以下依赖项添加到我的 Podspec

s.dependency 'Apollo/WebSocket', :git => 'https://github.com/apollographql/apollo-ios'

Here's what I get in my Terminal whenever I try to run pod lib lint MyPodName.podspec :每当我尝试运行pod lib lint MyPodName.podspec时,我都会在终端中得到以下pod lib lint MyPodName.podspec

- ERROR | spec: The specification defined in `MyPodName.podspec` could not be loaded.


[!] Invalid `MyPodName.podspec` file: [!] Unsupported version requirements.

 #  from <PathToMyPodspec>/MyPodName.podspec:36
 #  -------------------------------------------
 #    
 >    s.dependency 'Apollo/WebSocket', :git => 'https://github.com/apollographql/apollo-ios'
 #    
 #  -------------------------------------------

I have successfully used it as a Pod in one of my iOS projects.我已经成功地将它用作我的一个 iOS 项目中的 Pod。 But now that I am creating a pod myself, I am struggling to understand what I should do to make it work.但是现在我自己正在创建一个 pod,我很难理解我应该怎么做才能让它工作。

Thank you in advance!先感谢您!

It looks like it is not allowed to define dependency in PodSpec like this. 看起来不允许像这样在PodSpec中定义依赖项。 Please refer CocoaPod guideline document on Dependency 请参阅有关依赖关系的 CocoaPod指南文档

It seems it should contain only version information like mentioned below. 它似乎应该只包含如下所述的版本信息。 Other formats are not allowed. 不允许使用其他格式。

在此输入图像描述

While performing the validation, you need enter the command with the link to the repos where your podspecs are hosted.在执行验证时,您需要输入带有指向托管 podspec 的存储库链接的命令。 Something like this pod lib lint --sources=git@github.com:CocoaPods/Specs.git,git@github.com:otherRepos像这样的 pod lib lint --sources=git@github.com:CocoaPods/Specs.git,git@github.com:otherRepos

Solved! 解决了!

It turns out that the Podfile document of the project plays a major role in all of this. 事实证明,项目的Podfile文档在所有这些中起着重要作用。 I found it inside the /Example folder of said project. 我发现它在所述项目的/Example文件夹中。 What I've done is: 我所做的是:

use_frameworks!
source = 'https://github.com/apollographql/apollo-ios'
source = 'https://github.com/apollographql/apollo-ios'

target 'MyPodName_Example' do

  pod 'Apollo'
  pod 'Apollo/WebSocket'
  pod 'MyPodName', :path => '../'

  target 'MyPodName_Tests' do
    inherit! :search_paths


  end
end

(I am not quite sure if I necessarily need both of the source lines but it does work like this) (我不太确定我是否一定需要两个source行,但确实如此工作)

Then I ran pod install on the /Example directory. 然后我在/Example目录上运行pod install

After that I returned back to my MyPodName.podspec file and edited dependencies to look like this: 之后,我返回到MyPodName.podspec文件并编辑了依赖项,如下所示:

  s.dependency 'Apollo'
  s.dependency 'Apollo/WebSocket'

Then I ran pod lib lint MyPodName.podspec on the root directory (where my .podspec file is) and this time it succeeded. 然后我在根目录(我的.podspec文件所在的位置)上运行了pod lib lint MyPodName.podspec ,这次它成功了。


NOTICE: 注意:

  • I needed both Apollo and Apollo/WebSocket dependencies. 我需要ApolloApollo/WebSocket依赖项。
  • I haven't yet pushed my Pod and cannot guarantee that all of this is 100% correct 我还没推过我的Pod,也无法保证所有这一切都是100%正确的
  • I'm new to CocoaPods, so this might not be the most optimal solution to the problem. 我是CocoaPods的新手,所以这可能不是解决问题的最佳解决方案。

According to this CocoaPods/issues/2485 , CocoaPods/issues/922 , the podspecs cannot specify the source of dependencies now. 根据这个CocoaPods / issues / 2485CocoaPods / issues / 922 ,podspecs现在无法指定依赖关系的来源。

Alternative: 替代方案:

For public repo : 对于公共回购

Just use s.dependency 'Apollo/WebSocket', '~> 0.0.1' directly. 只需直接使用s.dependency 'Apollo/WebSocket', '~> 0.0.1'即可。

If you're specifying a private repo 如果您要指定私人仓库

Free feel to follow this blog's step to create( pod repo push ) a private library. 随心所欲地按照这个博客的步骤创建( pod repo push )私人图书馆。 Then you should be able to specify your private project by using s.dependency 'YourPrivateProjectName', '~> 0.0.1' 然后你应该能够通过使用s.dependency 'YourPrivateProjectName', '~> 0.0.1'来指定你的私人项目s.dependency 'YourPrivateProjectName', '~> 0.0.1'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM