如何读取.xcconfig文件常量与红宝石使用它们作为Fastlane车道变量?
我试图用Fastlane与当前配置部署我的iOS应用程序:具有多个目标和多个环境的单个项目(使用.xccconfig文件)。我创建了3条车道:开发,测试版,发行版。这些车道采用“brand_name”作为参数,因此我可以为每个目标使用相同的车道。如何读取.xcconfig文件常量与红宝石使用它们作为Fastlane车道变量?
我想要实现的是“读取”目标的.xcconfig文件中的常量(例如PRODUCT_BUNDLE_IDENTIFIER
)并将其用作我车道中的变量。我设法通过创建和阅读包含目标的捆绑ID的yaml文件来完成此操作,但由于我已经在使用.xcconfig文件,因此我想避免重复操作。我做了一些搜索找到答案,但由于我对ruby比较陌生,所以现在我被困住了。有没有办法做到这一点?
如果有帮助,这里是目前我使用的是在部分的注释工作车道我想用一个.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
谢谢
有关通过目标/配置直接打开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
我一直工作在一个类似的任务,并已发现瑟的解决方案ems工作。回答您的问题,我们可以打开.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