Integrating pods with all targets
Asked Answered
P

4

21

I have been using CocoaPods for a few weeks now with my iOS app and it works perfectly with the one target I have been testing (let's call it "MainApp"). However, I now want to build a different target ("MyAppLite") and noticed that the build failed (file not found on one of the pods' header files).

The differences in the Build Settings I've noticed are as follows:

  • Other Linker Flags does not contain the required frameworks in MyAppLite
  • Framework/Header/Library Search Paths are all empty in MyAppLite
  • None of the User-Defined Build Settings in MainApp are present in MyAppLite

How can I ensure that when I run pod install, all targets have the libraries linked?

For reference, here is my Podfile:

platform :ios, '5.0'

pod 'TTTAttributedLabel', '~> 1.7.0'
pod 'iRate', '~> 1.7.5'
pod 'MBProgressHUD', '~> 0.6'
pod 'FlurrySDK', '~> 4.2.3'
pod 'ACSimpleKeychain', '~> 0.0.1'
pod 'WEPopover', '~> 0.0.1'
pod 'AFNetworking', '~> 1.3.1'
pod 'Nimbus', '~> 1.0.0'
pod 'QuincyKit', '~> 2.1.9'
Polyhymnia answered 29/8, 2013 at 9:54 Comment(0)
P
42

For CocoaPods 1.0.0, recommendation from devs is using abstract_target (but not compatible with 0.39.0):

platform :ios, '5.0'

abstract_target 'defaults' do
    pod 'TTTAttributedLabel', '~> 1.7.0'
    pod 'iRate', '~> 1.7.5'
    pod 'MBProgressHUD', '~> 0.6'
    pod 'FlurrySDK', '~> 4.2.3'
    pod 'ACSimpleKeychain', '~> 0.0.1'
    pod 'WEPopover', '~> 0.0.1'
    pod 'AFNetworking', '~> 1.3.1'
    pod 'Nimbus', '~> 1.0.0'
    pod 'QuincyKit', '~> 2.1.9'

    target 'MyApp'
    target 'MyAppLite'
end

For CocoaPods 0.39.0 + 1.0.0 compatibility, using def works fine (but isn't recommended by devs):

platform :ios, '5.0'

def default_pods
    pod 'TTTAttributedLabel', '~> 1.7.0'
    pod 'iRate', '~> 1.7.5'
    pod 'MBProgressHUD', '~> 0.6'
    pod 'FlurrySDK', '~> 4.2.3'
    pod 'ACSimpleKeychain', '~> 0.0.1'
    pod 'WEPopover', '~> 0.0.1'
    pod 'AFNetworking', '~> 1.3.1'
    pod 'Nimbus', '~> 1.0.0'
    pod 'QuincyKit', '~> 2.1.9'
end

target 'MyApp' do
    default_pods
end

target 'MyAppLite' do
    default_pods
end
Prowl answered 20/1, 2016 at 16:24 Comment(0)
A
21

With CocoaPods 1.x

You can use the target blocks

platform :ios, '13.0'


def default_pods
    pod 'TTTAttributedLabel', '~> 1.7.0'
    pod 'iRate', '~> 1.7.5'
    pod 'MBProgressHUD', '~> 0.6'
    pod 'FlurrySDK', '~> 4.2.3'
    pod 'ACSimpleKeychain', '~> 0.0.1'
    pod 'WEPopover', '~> 0.0.1'
    pod 'AFNetworking', '~> 1.3.1'
    pod 'Nimbus', '~> 1.0.0'
    pod 'QuincyKit', '~> 2.1.9'
end

target 'MyApp' do
  default_pods
end

target 'MyAppLite' do
  default_pods
end

Relevant documentation

Anarthrous answered 29/8, 2013 at 10:51 Comment(5)
This is essentially what I did, but I had to define an explicit target containing all pods, followed by the line link_with ['MyApp', 'MyAppLite'] before the list of pods.Polyhymnia
Can I ask why you had to do so?Anarthrous
Yeah, probably an unrelated typo or something. It works great now.Polyhymnia
note with version 1.2.0, this no longer works. [!] Invalid Podfile file: [!] The specification of link_with in the Podfile is now unsupported, please use target blocks instead..Percussive
This answer works for meCauthen
P
9

If you have large number of targets and don't want to add new target each time, you can use this

def common_pods

   pod 'TTTAttributedLabel', '~> 1.7.0'
   pod 'iRate', '~> 1.7.5'
   pod 'MBProgressHUD', '~> 0.6'
   pod 'FlurrySDK', '~> 4.2.3'
   pod 'ACSimpleKeychain', '~> 0.0.1'
   pod 'WEPopover', '~> 0.0.1'
   pod 'AFNetworking', '~> 1.3.1'
   pod 'Nimbus', '~> 1.0.0'
   pod 'QuincyKit', '~> 2.1.9'

end

project = Xcodeproj::Project.open “./<projectNameHere>.xcodeproj"

project.targets.each do |t|

target t.name do

    common_pods

end
Patriarchy answered 15/6, 2018 at 11:31 Comment(1)
Hi, it's not working. It's giving error: [!] Invalid Podfile` file: syntax error, unexpected end-of-input, expecting end.`Caskey
N
3

From the docs:

If no explicit target is specified, then the Pods target will be linked with the first target in your project.

You can use link_with to link with further targets.

Also see Multiple Targets in the Cocoapods documentation if you need different dependency configurations for different targets

Natachanatal answered 29/8, 2013 at 9:59 Comment(2)
Build Settings are set automatically with pod install - I don't want to start manually messing with things that should be correctly automatically generated - isn't that the whole point of CocoaPods?Polyhymnia
Also, I want to set exactly the same dependencies for all targets.Polyhymnia

© 2022 - 2024 — McMap. All rights reserved.