2017-03-03 31 views
3

我有一個包含多個目標/方案的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權利,我必須手動生成它們。我希望它在每個目標到期時自動創建新的配置配置文件。

回答

5

我不知道提供這種功能的任何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 
+0

感謝您的信息。請看我更新的答案。我能夠返回值,但返回$(PRODUCT_BUNDLE_IDENTIFIER)而不是實際的捆綁ID。 – codeman

+0

它的工作!謝謝! – codeman

+1

不客氣!我已經發布了這個插件。要安裝它,請從命令行運行'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')' –

相關問題