ChatGPT解决这个技术问题 Extra ChatGPT

How to add custom project configurations to Xcode when using CocoaPods?

I have an iOS/OS X Xcode projects, where I'm using CocoaPods, and I can't seem to figure out how to add my own project configurations (In addition to Debug and Release) without completely blowing up the build.

In the project, I have a number of targets, for apps on both platforms and its app extensions. The Xcode workspace of course also has the Pods project.

Because the project builds targets for iOS and Mac, I use CocoaPods "targets" to group their pods together. My Podfile looks something like this:

source 'https://github.com/CocoaPods/Specs.git'

target :iOS do
  platform :ios, '7.1'
  link_with 'iOS', 'NozbeToday', 'NozbeShare', 'NozbeWatch'

  # pods...
end

target :Mac do
  platform :osx, '10.9'
  link_with 'Mac'

  # pods...
end

Now here's where I have a problem. So far I've had only the default "Debug" and "Release" configurations in my project. I wanted to change them and add some new ones for different provisioning profile/bundle ID combination.

… and I'm stuck. I can't figure out how to do this.

First sign of the problem was a warning pod install spewed out for every target/configuration combination:

[!] 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 NozbeToday to Pods/Target Support Files/Pods-iOS/Pods-iOS.dev debug.xcconfig or include the Pods/Target Support Files/Pods-iOS/Pods-iOS.dev debug.xcconfig in your build configuration.

I couldn't figure out what it means and how to fix this. Either way, the project wouldn't build — in the best case scenario I would get a linker error saying that it can't find Pods-something.a


o
occulus

OK, so half-way through writing this question I figured it out myself (yay rubber ducking). Here's the solution for next generations:

Essentially, you have to add an explicit dependency on the Pods target to your application scheme.

The way you do it, is: edit your application scheme, go to the Build section, and add the Pods target above your application target. You should see something like this:

https://i.stack.imgur.com/bs3KG.png

And it will just work.

As for the CocoaPods warnings on pod install, you need to use the xcconfig files generated by CP for each of your Xcode configurations. The way you do it is:

find the .xcconfig files in Pods/Target Support Files

drag and drop them to "Pods" group in your Xcode project (add reference only. Don't copy to target or add to the build)

Click on the project in project navigator, and select the project itself (not one of targets). Go to Info, and under Configurations set the right .xcconfigs to each configuration and target in the "Based on Configuration file" column.

You'll also need something like this in your Podfile to let CocoaPods know which of your Xcode configurations are "debug" (unoptimized), which are "release":

project '1Nozbe', {
  'iOS 1 Dev Debug' => :debug,
  'iOS 2 Dev AdHoc' => :release,
  'iOS 3 Release Debug' => :debug,
  'iOS 4 Release AdHoc' => :release,
  'iOS 5 Release AppStore' => :release,
}

Not exactly related to CocoaPods, but if you happen to have some other (sub-project) dependencies other than CP, you'll also need to do two things:

add explicit dependencies on the sub-project target (like on the screenshot above)

rename/add configurations in your sub-project so that they are the same as your main project. (Otherwise, Xcode just doesn't know which configuration to use with your sub-project)


rename/add configurations in your sub-project so that they are the same as your main project. (Otherwise, Xcode just doesn't know which configuration to use with your sub-project) Did you find this in a reference document or just based on experience?
@Tony this is just based on trial&error, not claiming it cannot be done.
[!] xcodeproj was renamed to project. Please update your Podfile accordingly.
I also added the same build configs with same names manually to Pods project and then did a pod install.This updated my .xcconfig files' names. Then I added the updated names like mentioned in the answer.
This xcodeproj '1Nozbe', { 'iOS 1 Dev Debug' => :debug, 'iOS 2 Dev AdHoc' => :release, 'iOS 3 Release Debug' => :debug, 'iOS 4 Release AdHoc' => :release, 'iOS 5 Release AppStore' => :release } Was the the whole thing, just in case someone is using Cocoapods version after 1.0 the xcodeproj is deprecated now the name is project Thank you!
l
leavez

Add this line in your config file, just like import a header file:

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

NOTE: it's #include, not #import


no more working with newer Xcode version, any explanation?
r
rgkobashi

Another solution without the need to add explict dependencies to any schema nor draging and dropping stuff:

How to add custom project configurations to Xcode when using CocoaPods

Usually when you add custom configurations to your xcode project (other than Debug and Release) the thing you should do is run pod install. This will fix/remake the changes that cocoapods usually do.

How to get ride of CocoaPods did not set the base configuration of your project because... warning

On the Configurations settings under Info tab, on project level, you need to set the base configuration to use (generated when running pod install)

And dont forget to tell cocoapods what config it should use, in other words map your condfigurations with pods configurations, otherwise your compile time might dramatically increase


d
devjme

What fixed it for me was:

Adding the includes to the custom config files, Adding the project config dependencies in the pod file (use the names that you see under info -> configurations and Then re-running pod install.

Here is the include for the config file (SupportingFiles->Config->ConfigFiles)

#include "Pods/Target Support Files/Pods-ProjectName/Pods-ProjectName.release prod.xcconfig"

Links that helped me:

Great Tutorial on setting up configs with Cocoapods

Project documentation Cocoapods

https://i.stack.imgur.com/96CIF.png

UPDATED

https://i.stack.imgur.com/tvOCK.png

https://i.stack.imgur.com/47Hj8.png


I think you're using the same xcconfig file for both Debug Dev and Release Dev. Now there a question of which of them should be imported in Development.xcconfig file, should it be the release dev.xcconfig or debug dev.xcconfig?
I have a config file for each of those items. They are not different bc they inherit from my same base dev file, but I did it that way so that I could make changes per env in the future. I added a few more pix above
I see so you use 1 more to pair an env with Release and Dev. So 3 envs and 2 build variants 5 for each target. If needed special change to a target that number doubles in this case (I think you still need to import separate pod configs so can't get away a lot of duplications in my case). I wish there would be some sort way to execute an if logic inside configs to check which target is using it. Thanks for the clarification.
When Cocoapods errors it will tell you what target it is using, and then it told me what files to add it to. Explicitly you tell it this in the pod file : project 'ProjectName', 'Debug Dev' => :debug, 'Debug QA' => :debug, 'Debug Prod' => :debug, 'Release Dev' => :release, 'Release QA' => :release, 'Release Prod' => :release
You have 5 targets for each configuration, but use the same xcconfig file for all of them. As I understood in i.e DevRelease file you include all your targets pods xcconfig files as well (#include "Pods/.." x5 per target in each conf). That means all your targets will share all your dependencies. For instance, you have a notification and a network extension target. Both of them will share all dependencies. That may create some compile time issues like using app specific API on extensions, but worst can lead up to run time issues hard to debug. Maybe I got it wrong, but that's what I understood