Search code examples
iosxcodecocoapodspodfile

Avoid explicitly stating every target in Podfile with Cocoapods 1.x


I have over 20 targets in my XCode project, and I often add or remove one.

Cocoapods v0.x created libPods.a which was linked to all my targets.

Now, with Cocoapods v1.x, I seem to have to specify every target in the Podfile. It creates over 20 identical library files, and if I change the targets, I have to update the Podfile and run pod install again.

I cannot find a way to just make "libPods.a" or "libPods-common.a". Using abstract_target, it just complains that there are no concrete targets unless I specify real targets (the thing I am trying to avoid).

I could get it to make libPods-first_target_name.a, and link that to the other targets but the library name would be incorrect and confusing in the other targets.

I think I will make a dummy 'common' target in the project and use that target in the Podfile to get my library built, but surely there is a better way?


Solution

  • I'm not sure it completely solves your problem but I use this in my podfile.

    project 'MyProject'
    platform :ios, '9.0'
    
    pod 'MagicalRecord', '~> 2.3'
    # etc..
    
    for t in Xcodeproj::Project.open("MyProject.xcodeproj").targets.select { |t| t.is_a?(Xcodeproj::Project::Object::PBXNativeTarget) } do
        target t.name
    end
    

    You don't have to explicitly define all target names, this short ruby code adds all Pods to all project targets.

    Hope it will help at least a little!