I'm using CocoaPods with my Xcode 4 project and I have three targets for my project (the default, one for building a lite version and one for building a demo version). All the targets use the same libraries, but CocoaPods is only adding the static library and search paths to the primary target. My podfile looks like this:
platform :ios, '5.0'
pod 'TestFlightSDK', '>= 1.1'
pod 'MBProgressHUD', '0.5'
pod 'iRate', '>= 1.6.2'
pod 'TimesSquare', '1.0.1'
pod 'AFNetworking', '1.1.0'
pod 'KKPasscodeLock', '0.1.5'
pod 'iCarousel', '1.7.4'
The only way I was get this to work was to specify each target individually with all the the pods listed again.
platform :ios, '5.0'
target :default do
pod 'TestFlightSDK', '>= 1.1'
pod 'MBProgressHUD', '0.5'
pod 'iRate', '>= 1.6.2'
pod 'TimesSquare', '1.0.1'
pod 'AFNetworking', '1.1.0'
pod 'KKPasscodeLock', '0.1.5'
pod 'iCarousel', '1.7.4'
end
target :lite do
link_with 'app-lite'
pod 'TestFlightSDK', '>= 1.1'
pod 'MBProgressHUD', '0.5'
pod 'iRate', '>= 1.6.2'
pod 'TimesSquare', '1.0.1'
pod 'AFNetworking', '1.1.0'
pod 'KKPasscodeLock', '0.1.5'
pod 'iCarousel', '1.7.4'
end
target :demo do
link_with 'app-demo'
pod 'TestFlightSDK', '>= 1.1'
pod 'MBProgressHUD', '0.5'
pod 'iRate', '>= 1.6.2'
pod 'TimesSquare', '1.0.1'
pod 'AFNetworking', '1.1.0'
pod 'KKPasscodeLock', '0.1.5'
pod 'iCarousel', '1.7.4'
end
Is there a better way to do this?
Easiest way is to use an abstract target, where each pod specified will be linked with all targets.
CocoaPods 1.0 has changed the syntax for this. It now looks like this:
OUTDATED Pre CocoaPods 1.0 answer:
Yes there is a better way! Check out
link_with
where you can dolink_with 'MyApp', 'MyOtherApp'
to specify multiple targets.I use this with unit tests like
link_with 'App', 'App-Tests'
(beware of spaces in target's names).Example:
2017 update
You can use abstract_target
I think better solution is
Reference from : http://natashatherobot.com/cocoapods-installing-same-pod-multiple-targets/
If you want multiple targets to share the same pods, use an abstract_target.
or just
source: https://guides.cocoapods.org/using/the-podfile.html