Bas*_*lba 5 ruby xcconfig ios fastlane
我正在尝试使用当前配置使用 Fastlane 部署我的 iOS 应用程序:具有多个目标和多个环境的单个项目(使用 .xccconfig 文件)。我创建了 3 个通道:开发、测试、分发。这些车道采用“brand_name”作为参数,因此我可以为每个目标使用相同的车道。
我想要实现的是“读取”目标的 .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
Run Code Online (Sandbox Code Playgroud)
谢谢
小智 5
我一直在从事类似的任务,并找到了一个似乎有效的解决方案。回答你的问题,我们可以打开.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
Run Code Online (Sandbox Code Playgroud)
但我发现它是一个相当肮脏的解决方案,因为仍然存在一些重复:我们已经在 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
Run Code Online (Sandbox Code Playgroud)
小智 0
直接打开 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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2118 次 |
| 最近记录: |