【问题标题】:How do I include my own xcconfigs when using Cocoapods?使用 Cocoapods 时如何包含我自己的 xcconfigs?
【发布时间】:2016-11-27 22:04:48
【问题描述】:

有没有办法在 Podfile 中指定 xcconfig 文件应该是 Cocoapods 生成的文件中的 #included?

是否有用于附加此 #include 的公开方法/变量,或者我是否需要阅读生成的 xcconfig 并将其与附加文本一起反刍?

比如在生成的Pods-SomeTarget.[configuration].xcconfig中,我想看看:

#include "my_other_config.xcconfig" //<-- I want this to be inserted

FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_ROOT}/Crashlytics" "${PODS_ROOT}/Fabric" "${PODS_ROOT}/Google-Mobile-Ads-SDK/Frameworks" "${PODS_ROOT}/GoogleAds-IMA-iOS-SDK-For-AdMob/GoogleInteractiveMediaAds/GoogleInteractiveMediaAds-GoogleIMA3ForAdMob" "${PODS_ROOT}/NewRelicAgent/NewRelicAgent" "${PODS_ROOT}/TwitterCore/iOS" "${PODS_ROOT}/TwitterKit/iOS"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1

【问题讨论】:

  • 你到底想要什么#include?​​span>
  • @Larme 添加了一个示例。
  • 您可以在您的 podfile 中使用 post_install 来执行此操作:(一位同事在我们的一个项目中这样做了)post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| xcconfig_path = config.base_configuration_reference.real_path puts xcconfig_path xcconfig = File.read(xcconfig_path) common_xcconfig = '#include "my_other_config.xcconfig"' File.open(xcconfig_path, "w") { |file| file &lt;&lt; common_xcconfig file.puts file &lt;&lt; xcconfig } end end end

标签: cocoapods xcode8 xcconfig podfile


【解决方案1】:

将这些行分别包含在您的调试和发布 xcconfig 文件中:

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

然后单击您的项目并在左侧的详细导航栏中从当前目标切换到您的项目并选择顶部的信息。将项目设置为使用您的基本/共享配置文件和调试/发布以指向您的 xcconfig 文件。

【讨论】:

  • 在有多个目标时如何使这项工作发挥作用的任何提示? Pods-Used 只是一个特定的目标。谢谢!
  • @DavidHodge Cocoapods 应该为每个目标生成一个单独的配置文件,除了每个构建配置。因此,对于两个目标和两个构建配置,您应该有 4 个配置文件。
猜你喜欢
  • 1970-01-01
  • 2019-12-06
  • 1970-01-01
  • 2015-12-23
  • 2013-07-30
  • 1970-01-01
  • 1970-01-01
  • 2021-09-09
  • 2019-03-08
相关资源
最近更新 更多