Cocoapods: How can I declare dependency from subspec 'A' to subspec 'B'

Created on 5 Jan 2017  Â·  8Comments  Â·  Source: CocoaPods/CocoaPods

I am trying to figure how I can declare a subspec dependency from B to A when subspec B is depend on subspec A in the podspec file as below.

Pod::Spec.new do |s|
  s.name         = "MyLib-SDK"
  s.version      = "1.0"
  s.summary      = "My Library"
  s.homepage     = "http://myhomepage.com"

  s.ios.deployment_target = "8.0"
  s.ios.frameworks = "Foundation", "UIKit", "SystemConfiguration", "Security", "CoreTelephony", "WebKit"

  s.source       = { :git => "https://github.com/myhome/ios-project.git", :tag => "1.0" }

  s.subspec 'MyLibrary-A' do |libOne|
    libOne.source_files  = "Headers", "Headers/**/*.h"
    libOne.exclude_files = "Headers/Exclude"
    libOne.resources = "SharedAssets/*"

    libOne.libraries = "z","sqlite3" #Zlib for gzip, sqlite3 for event store
    libOne.vendored_library = "libMyLibrary_A.a"
  end

  s.subspec 'MyLibrary-B' do |libTwo|
    libTwo.source_files  = "Headers", "Headers/**/*.h"
    libTwo.exclude_files = "Headers/Exclude"
    libTwo.resources = "SharedAssets/*"
    libTwo.dependency 'MyLibrary-A'

    libTwo.libraries = "sqlite3" # sqlite3 for db
    libTwo.vendored_library = "libMyLibrary_B.a"
  end

 end

Report

What did you do?

ℹ pod spec lint <mybodspecfile> --verbose

What did you expect to happen?

ℹ validation passed

What happened instead?

ℹ - ERROR | [iOS] unknown: Encountered an unknown error (Unable to find a specification for MyLibrary-A depended upon by MyLibrary-B

Most helpful comment

Generally, you just do s.dependency = <podname>. Subspecs are identified by name like so: /. AFNetworking does this. Have a look at their spec as an example: https://github.com/AFNetworking/AFNetworking/blob/master/AFNetworking.podspec

All 8 comments

+1

In my case Lib-A and Lib-B are 2 different targets. So Lib-B has import Lib-A throughout. And a user of the repo should be able to use both modules e.g. import Lib-A and import Lib-B where required.

Hey there, this looks like a great example of a question that you should ask on StackOverflow - there is an active tag CocoaPods where people can help out with questions like this. We try to keep the CocoaPods issues focused only on bug reports for the tool, and for upcoming feature requests. Which this doesn't look like.

Sounds like you know the solution then if it's not a bug, could you provide it?

@orta could a bug include a lack of documentation for a feature?

@rex-remind101 @orta This question is actual related to bug reported at: https://github.com/CocoaPods/CocoaPods/issues/6309

Since someone suggested to go around this problem by declaring dependency on the subspec to avoid duplicated symbol problem.

Generally, you just do s.dependency = <podname>. Subspecs are identified by name like so: /. AFNetworking does this. Have a look at their spec as an example: https://github.com/AFNetworking/AFNetworking/blob/master/AFNetworking.podspec

@benasher44 Yes, that appears to resolve dependency issue within the podspec although I still have other problem to resolve which is not related to this post. Thank you so much!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

spencerkohan picture spencerkohan  Â·  3Comments

marzapower picture marzapower  Â·  3Comments

pronebird picture pronebird  Â·  3Comments

pallaviMN picture pallaviMN  Â·  3Comments

intelliot picture intelliot  Â·  3Comments