Cocoapods 1.0:多个目标相同pods

Cocoapods 1.0: same pods for multiple targets

我的 Xcode 项目使用自定义 .xcconfig 文件进行构建设置。我有 debug.xcconfig、beta.xcconfig 和 release.xcconfig。它们被添加到相同的 3 个构建配置的每个目标中:

我需要为所有目标集成所有 pods。然而,在进行 pod 安装时,Cocoapods 为每个目标生成 3 个 .xcconfig 文件,并期望将这些文件添加到每个目标,或包含在我的自定义 .xcconfig 文件中。消息内容如下:

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').

我无法将基本配置设置为 Cocoapods 生成的 xcconfig 文件。我需要将我的自定义 xcconfig 文件设置为基础,以便将我的构建设置应用于目标。所以我必须沿着包含路线走下去。 在 Cocoapods 0.x 中,我能够将这个包含在我的自定义 .xcconfig 文件中:

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

但是对于 Cocoapods 1.0,我应该做这样的事情(对于我的每个 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"

这样不好。我的项目有 12 个目标,这意味着我必须在我的 3 个自定义 .xcconfigs 中的每一个中放置 12 个包含,总共 36 个包含。一定有更好的办法。

我在我的 Podfile 中尝试了几种不同的方法,包括一个抽象目标,但结果总是一样的。 任何人都知道如何解决这个问题?

这是我的 Podfile 代码:

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

您不应在每个自定义目标配置中包含所有 pod 配置。每个目标配置应该只包含它自己的参考 pod 配置:

目标 1

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

目标 2

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

您的 PodFile 似乎是正确的,您还可以在 'myPods' 定义之前添加明确的目标类型

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

您的 xCode 配置(图片)似乎也正确,与我的工作项目的唯一区别是我在项目级别选择了 'none' 而不是 'Application'。

尝试关闭 xCode,删除所有 pods,然后再次 运行 pod install