Add Active Compilation Conditions/Custom Flags using fastlane

406 views Asked by At

I need to add / remove preprocessor macros dynamically through fastlane. I'm able to add custom values into custom fields (User Defined) but I couldn't add any flags into Active Compilation Conditions.


Here is my related lane ->

fastlane_version "2.6.0"

fastlane_require "xcodeproj"

lane :write_to_build_settings do |options|
    project = Xcodeproj::Project.open(
      File.join(File.expand_path('..'), ENV["XCODEPROJ_NAME"])
    )
    target = project.targets.find { |t| t.name == options[:target] }

    if options[:configuration].nil?
      target.build_configurations.each do |c|
        c.build_settings[options[:field]] = options[:value]

        # This is what I've tried and I want!!
        # Maybe I should use `build_configuration` instead of `build_settings`
        c.build_settings[options["CUSTOM_FIELD"]] = "CUSTOM_VALUE"
      end
    else
      configuration = target.build_configurations.find { |c|
        c.name == options[:configuration]
      }
      configuration.build_settings[options[:field]] = options[:value]

      # This is what I've tried and I want!!
      # Maybe I should use `build_configuration` instead of `build_settings`
      if options[:option_to_add_flag]
        puts "option_to_add_flag: true"
        configuration.build_settings[options["CUSTOM_FIELD"]] = "CUSTOM_VALUE"
      end
      ### 
    end

    project.save
  end
0

There are 0 answers