我有一个包含多个目标/方案的 Xcode 项目设置,因此我在同一代码库下有多个应用程序。
我在我的 Fastfile 中创建了以下测试 channel ,它为我的每个应用程序运行“sigh”工具:
lane :testing do
["First", "Second", "Third", "Fourth"].each do |scheme_name|
sigh
end
end
查看 faSTLane 文档,我看到您可以定义 sigh 使用的包标识符。但我需要它自动从每个目标/方案的 plist 中获取当前的包标识符,并将其用于 sigh。这能实现吗?
类似于(伪代码):
bundle_id = get_bundle_id_from_plist
sigh(app_identifier: bundle_id)
我尝试使用这个插件:https://github.com/SiarheiFedartsou/fastlane-plugin-versioning它有一个获取 plist 路径的方法。然后我运行了这段代码:
bundle_id = get_info_plist_value(path: get_info_plist_path(target: scheme_name), key: 'CFBundleIdentifier')
puts bundle_id
输出是 $(PRODUCT_BUNDLE_IDENTIFIER),它实际上是 plist 值中的内容,所以我越来越接近了。但我需要它来返回实际的包 ID,而不仅仅是它指向的变量。
我想使用 sigh 的全部原因是因为每个应用程序/目标都有自己的配置文件,由于 CarPlay 权利,我最初必须手动生成这些配置文件。我希望它在每个目标过期时自动为每个目标创建新的配置文件。
最佳答案
我不知道有任何faSTLane
操作提供这样的功能,但您可以构建一个本地fastlane action ,或创建并分享 fastlane plugin ,它使用 code that updates an info plist using the scheme name 提供 CFBundleIdentifier
举个例子。
此代码使用 xcodeproj
Ruby gem 从方案中获取 Info.plist 文件。然后它更改 plist 值,然后保存 plist 文件。您可以做类似的事情,只是从 plist 返回 CFBundleIdentifier
。
如果您不想创建插件,我可以在本周晚些时候创建它,因为我对此很感兴趣。
在我完成插件之前,这段代码应该对你有用:
# At the top of your Fastfile; you may need to add "gem 'xcodeproj'" to your Gemfile and then do a bundle install
require 'xcodeproj'
def product_bundle_id(scheme)
project = Xcodeproj::Project.open('path/to/your/xcodeproj')
scheme = project.native_targets.find { |target| target.name == scheme }
build_configuration = scheme.build_configurations.first
build_configuration.build_settings['PRODUCT_BUNDLE_IDENTIFIER']
end
lane :testing do
["First", "Second", "Third", "Fourth"].each do |scheme_name|
sigh(app_identifier: product_bundle_id(scheme_name))
end
end
关于ios - 使用 faSTLane 根据方案/目标自动从 plist 获取包标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42590053/