使用fastlane自动根据方案/目标从plist获取包标识符
我有一个包含多个目标/方案的Xcode项目设置,因此我在同一代码库下有几个应用程序。使用fastlane自动根据方案/目标从plist获取包标识符
我创造了我的中fastfile下面的测试车道它运行我的应用程序的每一个“叹”工具:
lane :testing do
["First", "Second", "Third", "Fourth"].each do |scheme_name|
sigh
end
end
望着FASTLANE文档,我看你可以定义一个包标识符,叹息用途。但我需要它自动从每个目标/方案的plist中获取当前的包标识符,并用它来叹息。这可以完成吗?
类似的信息(伪码):
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,而不仅仅是它指向的变量。
我想要使用叹息的全部原因是因为每个应用程序/目标都有自己的供应配置文件,因为CarPlay权利,我必须手动生成它们。我希望它在每个目标到期时自动创建新的配置配置文件。
我不知道提供这种功能的任何fastlane
的行为,但是你可以建立一个本地fastlane action,或创建和共享一个fastlane plugin,即使用code that updates an info plist using the scheme name作为例子提供CFBundleIdentifier
。
此代码使用xcodeproj
Ruby gem从Scheme获取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
感谢您的信息。请看我更新的答案。我能够返回值,但返回$(PRODUCT_BUNDLE_IDENTIFIER)而不是实际的捆绑ID。 – codeman
它的工作!谢谢! – codeman
不客气!我已经发布了这个插件。要安装它,请从命令行运行'fastlane add_plugin get_product_bundle_id'。有关文档,请参阅https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Plugins.md。 要调用它,'get_product_bundle_id(project_filepath:project_path,scheme:'Scheme Name')' –