ivanzoid
ivanzoid

Reputation: 6062

Multiple targets depending on same cocoapods

I have multiple targets in Xcode project, which must depend on the same list of pods. I could write Podfile like this:

target :target1 do
    pod 'pod1'
    pod 'pod2'
    ...
end
target :target2 do
    pod 'pod1'
    pod 'pod2'
    ...
end

but it's obviously not cool.

I wish I could write something like this:

target :target1, :target2 do
    pod 'pod1'
    pod 'pod2'
end

but unfortunately it doesn't work. (Note that my main target do not need these pods). Is it possible to make multiple targets to depend on same list of pods (without copy-pasting of course)?

Upvotes: 3

Views: 2309

Answers (1)

Oly Dungey
Oly Dungey

Reputation: 1677

I have just been through this horrible situation and fixed it up - I now have a workspace that will build via command line or xcode that has 4 different targets with different bundle ID's. The problem with your approach above is that you end up with linking madness as each target will build the pods. What I did was:

  1. Create project with one target and pods configured.
  2. Copy the target 3 times and change bundle id's etc. using this link: http://swwritings.com/post/2013-05-20-concurrent-debug-beta-app-store-builds
  3. Create a workspace level scheme for each of your targets.
  4. Create a workspace level scheme for your pods build.
  5. Edit your schemes and turn off 'Find Implicit Dependencies'.
  6. Make your schemes depend on your pods scheme (build tab in edit schemes).

My podfile looks like this - just the same as it was at the start:

target 'test-target' do
    pod 'HockeySDK'
    pod 'RestKit', '~> 0.23.1'
    pod 'RKXMLReaderSerialization', :git => 'https://github.com/RestKit/RKXMLReaderSerialization.git', :branch => 'master'
    pod 'NSLogger'
    pod 'Parse-iOS-SDK'
end

I did have quite a few problems when building where it kept telling me it couldn't link to the pods build which I resolved by changing the 'Library Search Paths' in build settings to:

$(PROJECT_DIR)/Build/Products/$(CONFIGURATION)-$(PLATFORM_NAME)

It's a bit of a strange path with /Build/Products but that seems to be what Pods does out of the box and if you fight against it things get ugly.

It's hard to write a detailed how-to as it's taken me 5 days of experimentation to get the magic build working in Xcode, xcodebuild and our Teamcity CI server.

Upvotes: 1

Related Questions