Manage Dependencies of Multiple Targets with Cocoapods

戏子无情 提交于 2019-12-09 17:31:53

问题


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.

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?

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?

回答1:


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)



来源:https://stackoverflow.com/questions/14581386/manage-dependencies-of-multiple-targets-with-cocoapods

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!