Add Pod dependency with source to .podspec
Asked Answered
K

4

15

I am trying to add the following dependency to my 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:

- 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. But now that I am creating a pod myself, I am struggling to understand what I should do to make it work.

Thank you in advance!

Kilmarnock answered 18/4, 2019 at 12:20 Comment(2)
Still don't understand your problem. Are you getting any error or completely clueless on how to achieve something? Please explain.Lovelovebird
@Lovelovebird I'm sorry, my bad. I've extended my question, please, have a look.Kilmarnock
K
12

Solved!

It turns out that the Podfile document of the project plays a major role in all of this. I found it inside the /Example folder of said project. 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)

Then I ran pod install on the /Example directory.

After that I returned back to my MyPodName.podspec file and edited dependencies to look like this:

  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.


NOTICE:

  • I needed both Apollo and Apollo/WebSocket dependencies.
  • I haven't yet pushed my Pod and cannot guarantee that all of this is 100% correct
  • I'm new to CocoaPods, so this might not be the most optimal solution to the problem.
Kilmarnock answered 18/4, 2019 at 23:3 Comment(0)
L
16

It looks like it is not allowed to define dependency in PodSpec like this. Please refer CocoaPod guideline document on Dependency

It seems it should contain only version information like mentioned below. Other formats are not allowed.

enter image description here

Lovelovebird answered 18/4, 2019 at 16:16 Comment(2)
Yep, only a Podfile can specify locations for other podspecs.Press
Is there anything I could do?Kilmarnock
K
12

Solved!

It turns out that the Podfile document of the project plays a major role in all of this. I found it inside the /Example folder of said project. 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)

Then I ran pod install on the /Example directory.

After that I returned back to my MyPodName.podspec file and edited dependencies to look like this:

  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.


NOTICE:

  • I needed both Apollo and Apollo/WebSocket dependencies.
  • I haven't yet pushed my Pod and cannot guarantee that all of this is 100% correct
  • I'm new to CocoaPods, so this might not be the most optimal solution to the problem.
Kilmarnock answered 18/4, 2019 at 23:3 Comment(0)
P
7

According to this CocoaPods/issues/2485, CocoaPods/issues/922, the podspecs cannot specify the source of dependencies now.

Alternative:

For public repo:

Just use s.dependency 'Apollo/WebSocket', '~> 0.0.1' directly.

If you're specifying a private repo

Free feel to follow this blog's step to create(pod repo push) a private library. Then you should be able to specify your private project by using s.dependency 'YourPrivateProjectName', '~> 0.0.1'

Prophetic answered 13/6, 2019 at 13:2 Comment(1)
Hello boog: I tried same. But I get "No such module 'MyPrivatePOD'". Can you please see this question: #73147988Proudman
L
6

While performing the validation, you need enter the command with the link to the repos where your podspecs are hosted. Something like this pod lib lint [email protected]:CocoaPods/Specs.git,[email protected]:otherRepos

Lyons answered 9/5, 2021 at 16:26 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.