簡體   English   中英

如何使用ruby讀取.xcconfig文件常量以將它們用作Fastlane通道變量?

[英]How to read .xcconfig file constants with ruby to use them as Fastlane lane variables?

我正在嘗試使用當前配置使用Fastlane部署我的iOS應用程序:具有多個目標和多個環境的單個項目(使用.xccconfig文件)。 我創建了3個車道:開發,測試版,發行版。 這些車道采用“brand_name”作為參數,因此我可以為每個目標使用相同的車道。

我想要實現的是“讀取”目標的.xcconfig文件中的常量(例如PRODUCT_BUNDLE_IDENTIFIER )並將其用作我的通道中的變量。 我設法通過創建和讀取包含目標的bundle id的yaml文件來實現這一點,但由於我已經在使用.xcconfig文件,所以我希望避免重復。 我做了一些尋找答案,但由於我對紅寶石很新,我現在卡住了。 有沒有辦法實現這一目標?

如果它有幫助,這里是一個正在使用的工作通道,我正在使用.xcconfig文件而不是yaml文件對我要替換的部分進行注釋:

lane :development do |options|

    # Getting lane settings

    #adding lane_name to the options
    options = options.merge(lane_name: 'development') 

    # THIS IS THE PART I'D LIKE TO REPLACE WITH .XCCONFIG FILE INSTEAD OF YAML
    #fastlane config path
    config = YAML.load_file(File.join(File.dirname(__FILE__),"../Brand", options[:brand_name],"Configs/fastlane_config.yaml"))
    settings = OpenStruct.new(config)
    lane_settings = settings[options[:lane_name]]

    # Settings the App Identifier
    app_identifier = lane_settings["bundle_identifier"]

    pilot(skip_submission: true)
end

謝謝

我一直致力於類似的任務,並找到了似乎有效的解決方案。 回答你的問題,我們可以打開.xcconfig文件並按鍵讀取值。

lane :development do |options|
    fastlane_require 'Xcodeproj'

    # Compose .xcconfig file path
    configuration_file = "../Brand" + options[:brand_name] + "Configs/config.xcconfig"

    # Read values from the .xcconfig file
    configuration = Xcodeproj::Config.new(configuration_file)
    app_identifier = configuration.attributes['PRODUCT_BUNDLE_IDENTIFIER']

    ... 
end

但我發現它是一個非常臟的解決方案,因為仍然有一些重復:我們在Xcode項目中為目標/配置指定了一個配置文件,現在我們再次手動指定它。

一旦我們開始相互“繼承”(包含)配置文件,就會出現更多問題。 如果您有許多構建配置並且大多數共享相同的設置,它可能很有用,但只有一些設置因配置而異。

實現您最可能需要的方法的正確方法是通過合並所有適用的源來獲取標志值:項目,目標,配置,配置文件。 這可以通過從配置中獲取構建設置來完成,而不是從.xcconfig本身獲取。

lane :development do |options|
    fastlane_require 'Xcodeproj'


    # Here we can define some hardcoded values,
    # or read them from lane options,
    # or read them from environment variables...
    project_name = '../XXX.xcodeproj'
    target_name = 'YYY'
    configuration_name = 'ZZZ'

    # Read values from the configuration,
    # specified in project settings for a specific target.
    project = Xcodeproj::Project.open(project_name)
    target = project.native_targets.find {|s| s.name == target_name }
    configuration = target.build_configurations.find {|s| s.name == configuration_name}
    app_identifier = configuration.resolve_build_setting('PRODUCT_BUNDLE_IDENTIFIER')

    ...

end

如何直接打開Xcode項目並遍歷目標/配置以找到正確的:

lane :development do |options|

    # Getting lane settings

    #adding lane_name to the options
    options = options.merge(lane_name: 'development')

    project = '../PATH_TO_XCODE_PROJ'
    target = 'TARGET'
    buildConfiguration = 'BUILD_CONFIGURATION'
    app_identifier = ''

    project = Xcodeproj::Project.open(project)
    project.targets.each do |mtarget|
        if mtarget.name == target
            mtarget.build_configurations.each do |mbuild|
                if mbuild.name == buildConfiguration
                    app_identifier = mbuild.build_settings['PRODUCT_BUNDLE_IDENTIFIER']
                end
            end
        end
    end

    pilot(skip_submission: true)
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM