標籤:fast 函數 發布 下載 images 官網 輸入 undle 直接
Fastlane是一套使用Ruby寫的自動化工具集,用於iOS和Android的自動化打包、發布等工作,可以節省大量的時間。
Github:https://github.com/fastlane/fastlane
官網:https://fastlane.tools/
文檔:https://docs.fastlane.tools/
安裝
1、首先要安裝正確的 Ruby 版本。在終端視窗中用下列命令來確認:
ruby -v
2、然後檢查 Xcode 命令列工具是否安裝。在終端視窗中輸入命令:
xcode-select --install
如果未安裝,終端會開始安裝,如果報錯誤:command line tools are already installed, use "Software Update" to install updates.代表已經安裝。
3、以上依賴配置好之後就可以通過 rubygem 進行安裝了:
$ sudo gem install fastlane
安心等待一會,fastlane就安裝完成了。
初始化
進入到工程目錄執行:
fastlane init
中間需要輸入開發人員帳號、密碼。
初始化之後目錄下多了一個fastlane目錄,內容:
Appfile
Appfile用來存放app_identifier,apple_id和team_id。 瞭解詳情,它的格式是這樣的:
app_identifier "com.xxx.xxx" # app的bundle identifierapple_id "[email protected]" # 你的Apple ID team_id "XXXXXXXXXX" # Team ID
你也可以為每個lane(後面會講到)提供不同的 app_identifier, apple_id 和 team_id,例如:
app_identifier "com.aaa.aaa"apple_id "[email protected]"team_id "AAAAAAAAAA" for_lane :inhouse do app_identifier "com.bbb.bbb" apple_id "[email protected]" team_id "AAAAAAAAAA"end
這裡就是為Fastfile中定義的:inhouse設定單獨的資訊。
Fastfile
Fastfile管理你所建立的 lane ,瞭解詳情。它的格式是這樣的:
···# 自動更新fastlane 工具# update_fastlane #需要的fastlane的最小版本,在每次執行之後會檢查是否有新版本,如果有會在最後末尾追加新版本提醒fastlane_version "2.30.1" #預設使用平台是 ios,也就是說檔案可以定義多個平台default_platform :ios platform :ios do before_all do # ENV["SLACK_URL"] = "https://hooks.slack.com/services/..." cocoapods end desc "Runs all the tests" lane :test do scan end desc "提交一個新的Beta版本到 Apple TestFlight" desc "This will also make sure the profile is up to date" lane :beta do # match(type: "appstore") # more information: https://codesigning.guide gym(scheme: "Docment") # Build your app - more options available pilot # sh "your_script.sh" end desc "部署一個新版本到App Store" lane :release do # match(type: "appstore") # snapshot gym(scheme: "Docment") # Build your app - more options available deliver(force: true) # frameit end # 你可以定義自己的lane #執行lane成功後的回調 after_all do |lane| # slack( # message: "Successfully deployed new App Update." # ) end # 如果流程發生異常會走這裡並終止 error do |lane, exception| # slack( # message: exception.message, # success: false # ) endend
我們也可以定義一個自己的lane:
desc "企業版" lane :inHouse do gym(scheme: "XXX", export_method:"enterprise", output_directory "./build", # 打包後的 ipa 檔案存放的目錄 output_name "XXX" # ipa 檔案名稱 ) end
其中一個lane就是一個任務,裡面是一個個的action組成的工作流程。
利用目前支援的工具可以做所有包含自動化和可持續化構建的每個環節,例如:
scan 自動化測試載入器,很好的封裝了 Unit Test
sigh 針對於 iOS 項目開發認證和 Provision file 的下載工具
match 同步團隊每個人的認證和 Provision file 的超贊工具
gym 針對於 iOS 編譯打包產生 ipa 檔案
deliver 用於上傳應用的二進位代碼,應用截屏和中繼資料到 App Store
snapshot 可以自動化iOS應用在每個裝置上的本地化截屏過程
執行
定義完lane之後怎麼執行呢?開啟終端,切換到項目的根目錄:執行fastlane lane‘name就可以了。成功之後會在相應的路徑下產生ipa檔案,如果報錯的話就根據錯誤資訊好好查看文檔。
其他
1、這裡是官方提供的一些例子。
2、想瞭解fastlane命令的話可以執行$ fastlane --help
3、查看可用任務的列表,可以執行命令$ fastlane lanes
4、fastlane也提供了很多外掛程式方便我們使用,例如pgyer(發布app到蒲公英)。我們也可以打完包直接傳到蒲公英上,具體的可以看蒲公英提供的文檔。
如果你感覺有些外掛程式不符合自己的情況,你甚至可以自訂外掛程式
5、多個 lane 的話實際上是可以相互調用的,這個其實特別實用。例如:
default_platform :ios platform :ios do lane :prepare do cocoapods match end desc ‘fastlane build‘ ‘fastlane build type:adhoc‘ lane :build do |options| # 調用上面的 prepare 任務 prepare case options[:type] when ‘adhoc‘ adhoc else appstore end end lane : adhoc do ··· end lane : appstore do ··· end end
6、我們可以在 Fastfile 檔案中添加一個函數來設定version號和build號。
default_platform :ios def prepare_version(options) increment_version_number( version_number: options[:version] ) increment_build_number( build_number: options[:build] )end
然後可以在一個lane中使用這個函數:
lane :appstore do |options| ··· prepare_version(options) ···end
然後執行這個lane的時候:
$ fastlane appstore version:2.4.0 build:2.0
Fastlane能做的事情還有很多,大家可以去好好看看文檔,研究一些進階的用法吧!
Fastlane- app自動編譯、打包多個版本、上傳到app store