iosxcodecocoapodsxcconfig

Cocoapods 1.0: same pods for multiple targets


My Xcode project uses custom .xcconfig files for build settings. I have a debug.xcconfig, beta.xcconfig and release.xcconfig. They're added to each target for the same 3 build configurations:

enter image description here

I need all my pods integrated for all targets. However, when doing a pod install, Cocoapods generates 3 .xcconfig files for each target and expects those to be added to each target, or included in my custom .xcconfig file. The message reads:

CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target 'Target1' to 'Pods/Target Support Files/Pods-Target1/Pods-Target1.debug.xcconfig' or include the 'Pods/Target Support Files/Pods-Target1/Pods-Target1.debug.xcconfig' in your build configuration ('MyProject/Configuration/Debug.xcconfig').

I can't set the base configuration to the Cocoapods generated xcconfig file. I need my custom xcconfig file to be set as the base, as to apply my build settings to the target. So I'll have to go down the include route. In Cocoapods 0.x I was able to just put this include in my custom .xcconfig files:

#include "../Pods/Target Support Files/Pods/Pods.debug.xcconfig"

But with Cocoapods 1.0, I'm expected to do something like this (for each of my xcconfigs):

#include "../Pods/Target Support Files/Pods-Target1/Pods-Target1.debug.xcconfig"
#include "../Pods/Target Support Files/Pods-Target2/Pods-Target2.debug.xcconfig"
#include "../Pods/Target Support Files/Pods-Target3/Pods-Target3.debug.xcconfig"
#include "../Pods/Target Support Files/Pods-Target4/Pods-Target4.debug.xcconfig"

This is not good. My project has 12 targets, which means I have to put 12 includes in each of my 3 custom .xcconfigs, totalling 36 includes. There must be a better way.

I've tried several different approaches in my Podfile, including an abstract target, but the result is always the same. Anyone knows how to solve this?

Heres my Podfile code:

platform :ios, '8.4'
use_frameworks!


def myPods

  pod 'SplunkMint'
  pod 'Alamofire', '~> 3.0'
  pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git'

end

target 'target1' do
    myPods
end

target 'target2' do
    myPods
end

target 'target3' do
    myPods
end

target 'target4' do
    myPods
end

Solution

  • You shouldn't include all the pod config in every custom target config. Each target config should include only it's own reference pod config:

    Target1

    #include "../Pods/Target Support Files/Pods-Target1/Pods-Target1.debug.xcconfig"
    

    Target2

    #include "../Pods/Target Support Files/Pods-Target2/Pods-Target2.debug.xcconfig"
    

    Your PodFile seems correct, you could also add the explicit target type before 'myPods' definition

    xcodeproj 'YourProjectName', {
        'Target1' => :release,
        'Target2' => :debug,
        'Target3' => :debug
        'Target4' => :debug
    }
    

    Your xCode configurations (the image) seems correct too, the only difference with my working project is that I have selected 'none' instead of 'Application' at project level.

    Try to close xCode, remove all the pods and then run again pod install