1、安裝
Ruby 2.0.0及以上版本
(1)使用 gem 安裝 fastlane
sudo gem install fastlane
(2)直接下載安裝:(https://github.com/fastlane/fastlane)

(3)確保 Xcode 命令行工具已安裝:
xcode-select --install
2、基本使用
(1)cd到工程所在的文件
(2)輸入命令
fastlane init
期間會要求輸入app 的id、密碼、bundle identifier等(如果在多個team會讓選擇哪個team)。
完成后會增加一個fastlane文件夾,里面有兩個文件Appfile、Fastfile。
(3)修改Fastfile,使用相關(guān)命令。
3、使用場景舉例
要求,按規(guī)定方式命名并把ipa和dSYM文件放到指定位置。
fastlane文件如下:
lane :dev_ipa do
cocoapods
increment_build_number
increment_version_number
build_number = get_build_number(xcodeproj: "appName.xcodeproj")
version = get_version_number(xcodeproj: "appName.xcodeproj")
time = Time.new
time_str = time.strftime("%Y%m%d")
current_path = File.expand_path("..")
out_put_path = current_path + time.strftime("%Y%m%d%H%M")
gym(
workspace: "appName.xcworkspace",
scheme: "appName",
clean: true,
output_directory: out_put_path,
output_name: "appName" + "-" + time.strftime("%Y%m%d") + "-" + version + "-v" + build_number + "-dev",
configuration: "Debug",
silent: true,
include_symbols: true,
include_bitcode: true,
export_method: "enterprise",
use_legacy_build_api: true,
increment_version_number,
)
end
4、命令的一些說明
workspace:"appName.xcworkspace”,#指定.xcworkspace文件的路徑。
scheme:"appName",#指定項目的scheme名稱,如果不設(shè)置會在終端里提醒設(shè)置
clean:true,#在打包前是否先執(zhí)行clean。
output_directory:"path/to/dir",#指定.ipa文件的輸出目錄,默認為當(dāng)前文件夾。
output_name:"appName",#指定生成的.ipa文件的名稱,應(yīng)包含文件擴展名。
configuration:"Debug",#指定打包時的配置項,默認為Release。證書要在Xcode里面配置好,關(guān)于配置證書請參考(https://docs.fastlane.tools/codesigning/xcode-project/)
silent:true,#是否隱藏打包時不需要的信息。
include_symbols:true, #是否生成符號表,默認true
include_bitcode:true,#是否開啟bitcode,默認true
export_method:"ad-hoc",#指定導(dǎo)出.ipa時使用的方法,可用選項:app-store, ad-hoc, package, enterprise, development, developer-id。默認:app-store。只有在證書完全匹配成功的情況下才能打出想要的包,一定要保證工程設(shè)置正確。
其它常用命令
獲取build:build_number = get_build_number(xcodeproj: "appName.xcodeproj")
獲取version:version = get_version_number(xcodeproj: "appName.xcodeproj")
獲取當(dāng)前文件的位置:current_path = File.expand_path("..")
獲取時間:time = Time.new ,time_str = time.strftime("%Y%m%d")
如果打包失敗添加:use_legacy_build_api: true,試一試。
版本號自動增加:increment_version_number,
build自動增加:increment_build_number
注:自動增加版本號需要配置,具體配置請參考官方文檔或使用fastlane自動增加版本號