使用fastlane根据方案/目标自动从plist获取包标识符

cod*_*man 5 ios fastlane

我有一个Xcode项目设置有多个目标/方案,所以我在同一个代码库下有几个应用程序.

我在我的Fastfile中创建了以下测试通道,它为我的每个应用程序运行"叹气"工具:

lane :testing do
  ["First", "Second", "Third", "Fourth"].each do |scheme_name|
      sigh
  end
end
Run Code Online (Sandbox Code Playgroud)

查看fastlane文档,我看到您可以定义一个包标识符,叹息使用.但我需要它自动从每个目标/方案的plist中获取当前的bundle标识符并用它来叹息.这可以实现吗?

像(伪代码):

bundle_id = get_bundle_id_from_plist
sigh(app_identifier: bundle_id)
Run Code Online (Sandbox Code Playgroud)

我尝试使用这个插件: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
Run Code Online (Sandbox Code Playgroud)

输出是$(PRODUCT_BUNDLE_IDENTIFIER),实际上是plist值,所以我越来越近了.但是我需要这个来返回实际的bundle id,而不仅仅是它指向的变量.

我想要使​​用叹息的全部原因是因为每个应用程序/目标都有自己的配置文件,我必须由于CarPlay权限而最初手动生成.我希望它在到期时自动为每个目标创建新的配置文件.

Lyn*_*son 8

我不知道fastlane提供此类功能的任何操作,但您可能能够构建本地fastlane操作,或创建和共享fastlane插件,该插件使用方案名称作为示例提供CFBundleIdentifier使用更新信息plist代码.

此代码使用xcodeprojRuby gem从Scheme获取Info.plist文件.然后它会更改plist值,然后保存plist文件.除了CFBundleIdentifier从plist 返回之外,你可以做类似的事情.

如果您不想创建插件,我可以在本周晚些时候创建它,因为这让我感兴趣.

在我完成插件之前,此代码应该适合您:

    # 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
Run Code Online (Sandbox Code Playgroud)

  • 不客气!我已经发布了插件。要安装它,请从命令行运行“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')` (2认同)