Cocoapods和自定义xcconfig

pas*_*ine 7 xcconfig ios cocoapods

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

sgl*_*l0v 5

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

#include "../Pods/Target Support Files/Pods-Demo/Pods-Demo.debug.xcconfig"
GCC_PREPROCESSOR_DEFINITIONS = ...
Run Code Online (Sandbox Code Playgroud)

在这种情况下,将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
    
    Run Code Online (Sandbox Code Playgroud)
  2. 以下一种方式定义 xcconfig 文件:

    #include "../Pods/Target Support Files/Pods-Demo/Pods-Demo.debug.xcconfig"
    GCC_PREPROCESSOR_DEFINITIONS = $(PODS_GCC_PREPROCESSOR_DEFINITIONS) ...
    
    Run Code Online (Sandbox Code Playgroud)

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