Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manage Dependencies of Multiple Targets with Cocoapods

I just started tinkering with cocoapods to manage dependencies of my iOS Projects. Currently I am trying to integrate unit tests using GHIOSUnit. I followed all their instructions and tried their sample tests and it all worked like charm.

Project Setup 1enter image description here

However, problems start when I start using my actual project files for testing.

I am using AFNetworking for client server comms and whenever I access my sharedClient called 'CRLClient', a wrapper for AFHTTPClient, it gives me undefined symbols errors.

Undefined symbols for architecture armv7:
  "_OBJC_METACLASS_$_AFHTTPClient", referenced from:
      _OBJC_METACLASS_$_CRLClient in CRLClient.o
  "_OBJC_CLASS_$_AFJSONRequestOperation", referenced from:
      objc-class-ref in CRLClient.o
  "_OBJC_CLASS_$_AFHTTPClient", referenced from:
      _OBJC_CLASS_$_CRLClient in CRLClient.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The pod file for managing dependencies looks like this

workspace 'Storyboards.xcworkspace'
platform :ios, '5.0'
pod 'AFNetworking', '1.1.0'
target :UnitTests, :exclusive => true do
pod 'GHUnitIOS', '0.5.6'
end

The actual project target builds fine and works with AFNetworking perfectly.

P.S. I am required to add all the files to be tested to be added to the UnitTest Target as well. Then what does adding 'Target Dependency' in build phases do?

enter image description hereenter image description here

In short,

  1. how to share common dependencies between different targets?
  2. what does adding target dependencies really do if I still have to add each file to new target?
like image 594
atastrophic Avatar asked Jan 29 '13 11:01

atastrophic


1 Answers

By using

target :UnitTests, :exclusive => true do
  pod 'GHUnitIOS', '0.5.6'
end

You're saying that the only library you want to be linked to the UnitTests target is GHUnit mainly saying you don't want AFNetworking to be linked as well. The problem is it looks like you're also importing your AFHTTPClient subclass into UnitTests where it can't find the AFNetworking components it's trying to link to.

To fix this you should be able to remove the exclusive call

target :UnitTests do
  pod 'GHUnitIOS', '0.5.6'
end

With this you will link GHUnit only to your UnitTests target but will link AFNetworking to both. "The target will by default include the dependencies defined outside of the block, unless the :exclusive => true option is given." (from here)

like image 118
Keith Smiley Avatar answered Oct 14 '22 07:10

Keith Smiley