gpt4 book ai didi

ios - 如何使用 ruby​​ 读取 .xcconfig 文件常量以将它们用作 FaSTLane channel 变量?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:54:24 25 4
gpt4 key购买 nike

我正在尝试使用具有当前配置的 FaSTLane 部署我的 iOS 应用程序:具有多个目标和多个环境的单个项目(使用 .xccconfig 文件)。我创建了 3 个 channel :开发、测试版、分发。这些泳道将“品牌名称”作为参数,因此我可以为每个目标使用相同的泳道。

我想要实现的是“读取”目标的 .xcconfig 文件中的常量(例如 PRODUCT_BUNDLE_IDENTIFIER)并将其用作我的 channel 中的变量。我设法通过创建和读取包含目标包 ID 的 yaml 文件来做到这一点,但由于我已经在使用 .xcconfig 文件,所以我想避免重复。我做了一些搜索以找到答案,但由于我对 ruby​​ 还很陌生,所以我现在被卡住了。请问有办法实现吗?

如果有帮助,这是我目前正在使用的工作 channel ,其中包含对我想使用 .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 项目中为 target/configuration 指定了一个配置文件,现在我们再次手动指定它。

一旦我们开始相互“继承”(包含)配置文件,就会出现更多问题。如果您有很多构建配置并且其中大部分共享相同的设置,但只有一些设置在不同配置中不同,它会很有用。

实现您最可能需要的正确方法是通过合并所有适用的源来获取标志值:项目、目标、配置、配置文件。这可以通过从您的配置获取build设置来完成,而不是从 .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

关于ios - 如何使用 ruby​​ 读取 .xcconfig 文件常量以将它们用作 FaSTLane channel 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44548017/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com