Cocoapods and custom xcconfig

I am trying to use Cocoapods with some custom configurations in an iOS project.
I have 3 (Dev, Stage, Prod) and each one has a custom GCC_PREPROCESSOR_DEFINITIONS . I have seen around people offering us #include <path-to-pods.xcconfig> , but this seems like an old way to do this.
I saw that Cocoapods 0.39 automatically generates its configuration files based on my configurations and automatically adds them to my goals (which is good).
This is also confirmed by this article , which talks about the β€œnew way” to create Podfiles. The problem is that these files do not contain my configurations.
I tried to use xcodeproj and link_with , but to no avail. Does anyone know how to handle Cocoapods + custom xcconfig files correctly?

+5
source share
1 answer

The problem is that CocoaPods is based on xcconfig files and sets the actual variables. But these values ​​cannot be used in any way when the full configuration is in xcconfig files, for example:

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

In this case, GCC_PREPROCESSOR_DEFINITIONS overwrites the previous value.

Here's how to solve it:

  • Update the GCC_PREPROCESSOR_DEFINITIONS to override the GCC_PREPROCESSOR_DEFINITIONS value with the PODS_ prefix in post_install:

     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 
  • Define the xcconfig file as follows:

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

In this case, GCC_PREPROCESSOR_DEFINITIONS should contain PODS_GCC_PREPROCESSOR_DEFINITIONS and custom values.

+2
source

Source: https://habr.com/ru/post/1246168/


All Articles