如何在使用CocoaPods时向Xcode添加自定义项目配置?

时间:2023-01-27 10:49:06

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.

我有一个iOS / OS X Xcode项目,我正在使用CocoaPods,我似乎无法弄清楚如何添加我自己的项目配置(除了Debug和Release)而没有完全炸毁构建。

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.

在该项目中,我有许多目标,适用于两个平台及其应用扩展的应用。 Xcode工作区当然也有Pods项目。

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

由于该项目为iOS和Mac构建了目标,因此我使用CocoaPods“目标”将其pod组合在一起。我的Podfile看起来像这样:

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.

现在我在这里遇到问题。到目前为止,我的项目中只有默认的“Debug”和“Release”配置。我想更改它们并为不同的配置文件/捆绑ID组合添加一些新的。

… 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:

问题的第一个迹象是针对每个目标/配置组合喷出的警告pod安装:

[!] 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.

[!] CocoaPods没有设置项目的基本配置,因为您的项目已经有自定义配置集。为了使CocoaPods集成完全可用,请将目标NozbeToday的基本配置设置为Pods / Target Support Files / Pods-iOS / Pods-iOS.dev debug.xcconfig或包括Pods / Target Support Files / Pods-构建配置中的iOS / Pods-iOS.dev debug.xcconfig。

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

我无法弄清楚它的意义以及如何解决这个问题。无论哪种方式,项目都不会构建 - 在最好的情况下,我会得到一个链接器错误,说它无法找到Pods-something.a ...

2 个解决方案

#1


34  

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

好吧,所以写这个问题的中途我自己想出来了(yay rubber ducking)。这是下一代的解决方案:

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

实质上,您必须在Pods目标上添加对应用程序方案的显式依赖。

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:

您这样做的方法是:编辑您的应用程序方案,转到Build部分,并将Pods目标添加到应用程序目标之上。你应该看到这样的东西:

如何在使用CocoaPods时向Xcode添加自定义项目配置?

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:

至于pod安装上的CocoaPods警告,您需要为每个Xcode配置使用CP生成的xcconfig文件。你这样做的方式是:

  • find the .xcconfig files in Pods/Target Support Files
  • 在Pods / Target Support Files中找到.xcconfig文件
  • drag and drop them to "Pods" group in your Xcode project (add reference only. Don't copy to target or add to the build)
  • 将它们拖放到Xcode项目中的“Pods”组中(仅添加引用。不要复制到目标或添加到构建中)
  • 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.
  • 单击项目导航器中的项目,然后选择项目本身(不是目标之一)。转到“信息”,然后在“配置”下,在“基于配置文件”列中为每个配置和目标设置正确的.xcconfigs。

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":

在Podfile中你也需要这样的东西让CocoaPods知道哪些Xcode配置是“debug”(未经优化),这是“发布”:

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:

与CocoaPods不完全相关,但如果您碰巧有除CP之外的其他(子项目)依赖项,您还需要做两件事:

  • 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)
  • 在子项目中重命名/添加配置,使它们与主项目相同。 (否则,Xcode只知道您的子项目使用哪种配置)

#2


4  

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

注意:它是#include,而不是#import

#1


34  

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

好吧,所以写这个问题的中途我自己想出来了(yay rubber ducking)。这是下一代的解决方案:

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

实质上,您必须在Pods目标上添加对应用程序方案的显式依赖。

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:

您这样做的方法是:编辑您的应用程序方案,转到Build部分,并将Pods目标添加到应用程序目标之上。你应该看到这样的东西:

如何在使用CocoaPods时向Xcode添加自定义项目配置?

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:

至于pod安装上的CocoaPods警告,您需要为每个Xcode配置使用CP生成的xcconfig文件。你这样做的方式是:

  • find the .xcconfig files in Pods/Target Support Files
  • 在Pods / Target Support Files中找到.xcconfig文件
  • drag and drop them to "Pods" group in your Xcode project (add reference only. Don't copy to target or add to the build)
  • 将它们拖放到Xcode项目中的“Pods”组中(仅添加引用。不要复制到目标或添加到构建中)
  • 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.
  • 单击项目导航器中的项目,然后选择项目本身(不是目标之一)。转到“信息”,然后在“配置”下,在“基于配置文件”列中为每个配置和目标设置正确的.xcconfigs。

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":

在Podfile中你也需要这样的东西让CocoaPods知道哪些Xcode配置是“debug”(未经优化),这是“发布”:

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:

与CocoaPods不完全相关,但如果您碰巧有除CP之外的其他(子项目)依赖项,您还需要做两件事:

  • 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)
  • 在子项目中重命名/添加配置,使它们与主项目相同。 (否则,Xcode只知道您的子项目使用哪种配置)

#2


4  

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

注意:它是#include,而不是#import