11

我正在尝试在 iOS 项目中使用带有一些自定义配置的 Cocoapods。
我有 3 个(Dev、Stage、Prod),每个都有一些 custom GCC_PREPROCESSOR_DEFINITIONS。我看到周围有人向我们建议#include <path-to-pods.xcconfig>,但这似乎是老方法。
我已经看到 Cocoapods0.39会根据我的配置自动生成其配置文件并将它们自动添加到我的目标中(这很好)。这篇文章
也证实了这一点,他正在谈论一种创建 Podfile 的“新方法”。问题是这些文件不包含我的配置。 我试图使用and ,但没有成功。有谁知道处理 Cocoapods + 自定义 xcconfig 文件的正确方法是什么?
xcodeprojlink_with

4

1 回答 1

5

问题是 CocoaPods 基于 xcconfig 文件并设置实际变量。但是当完整配置在 xcconfig 文件中时,这些值不能以任何方式使用,例如:

#include "../Pods/Target Support Files/Pods-Demo/Pods-Demo.debug.xcconfig"
GCC_PREPROCESSOR_DEFINITIONS = ...

在这种情况下GCC_PREPROCESSOR_DEFINITIONS会覆盖以前的值。

这是解决它的方法:

  1. 更新 Podfile 以在 post_install 上重新定义GCC_PREPROCESSOR_DEFINITIONS带有PODS_前缀的值:

    post_install do |installer|
        work_dir = Dir.pwd
        Dir.glob("Pods/Target Support Files/Pods-Demo/*.xcconfig") do |xc_config_filename|
            full_path_name = "#{work_dir}/#{xc_config_filename}"
            xc_config = File.read(full_path_name)
            new_xc_config = new_xc_config.sub(/GCC_PREPROCESSOR_DEFINITIONS/, 'PODS_GCC_PREPROCESSOR_DEFINITIONS')
            File.open(full_path_name, 'w') { |file| file << new_xc_config }
        end
    
    end
    
  2. 用下一种方式定义 xcconfig 文件:

    #include "../Pods/Target Support Files/Pods-Demo/Pods-Demo.debug.xcconfig"
    GCC_PREPROCESSOR_DEFINITIONS = $(PODS_GCC_PREPROCESSOR_DEFINITIONS) ...
    

在这种情况下GCC_PREPROCESSOR_DEFINITIONS,应该包含PODS_GCC_PREPROCESSOR_DEFINITIONS& 你的自定义值。

于 2017-09-27T22:31:58.547 回答