Fastlane 使用大致流程如下:
思路弄清楚后操作時(shí),參照demo中的文件修改即可。參數(shù)可以自定義配置(參數(shù)說明可查看官方文檔)

一.安裝fastlane
1.安裝最新的Xcode命令行工具:
xcode-select --install
2.使用安裝fastlane,下面兩種方法使用其中一個(gè)即可
sudo gem install fastlane -NV
或者:
brew cask install fastlane
Fastlane官方文檔https://docs.fastlane.tools/getting-started/ios/setup
現(xiàn)在對(duì)Appfile,F(xiàn)astfile,Gemfile,Deliverfile文件說明如下(后面會(huì)用到)
Appfile: 存儲(chǔ)有關(guān)開發(fā)者賬號(hào)相關(guān)信息
Fastfile: 核心文件,用于命令行調(diào)用和處理具體的流程,lane相對(duì)于一個(gè)action方法或函數(shù)
Gemfile 類似于cocopods 的Podfile文件
.env 配置環(huán)境變量(在fastlane init進(jìn)行初始化后并不會(huì)自動(dòng)生成,如果需要可以自己創(chuàng)建
Deliverfile: deliver工具的配置文件,上傳截圖蘋果和后臺(tái)一些app信息 (默認(rèn)不生成,需要sudo gem install deliver安裝)然后在fastlane 目錄下執(zhí)行deliver init 即可)
要注意的點(diǎn):
build_app命令等同于gym(別名)
deliver 命令相當(dāng)于upload_to_app_store(別名)
二. 使用(操作流程)
2.1 在項(xiàng)目目錄下執(zhí)行 fastlane init
新版本安裝的時(shí)候出現(xiàn)了下面的分支選擇,按要求選擇就行
1. ?? Automate screenshots (自動(dòng)截屏
2. ????? Automate beta distribution to TestFlight (自動(dòng)testfilght型配置)
3. ?? Automate App Store distribution (自動(dòng)發(fā)布型配置)
4. ?? Manual setup - manually setup your project to automate your (需要手動(dòng)配置內(nèi)容)
這里我們選擇4,然后一直按回車。會(huì)生成Gemfile文件,fastlane文件夾,Appfile,F(xiàn)astfile文件
Appfile: 存儲(chǔ)有關(guān)開發(fā)者賬號(hào)相關(guān)信息
Fastfile: 核心文件,用于命令行調(diào)用和處理具體的流程,lane相對(duì)于一個(gè)action方法或函數(shù)
Gemfile 類似于cocopods 的Podfile文件
.env 配置環(huán)境變量(在fastlane init進(jìn)行初始化后并不會(huì)自動(dòng)生成,如果需要可以自己創(chuàng)建
Deliverfile: deliver工具的配置文件,上傳截圖等 (默認(rèn)不生成,需要sudo gem install deliver安裝)然后在fastlane 下執(zhí)行deliver init 即可)#此處不使用,自己去蘋果后臺(tái)配置
注意:自動(dòng)生成的Gemfile里的路徑需要把'.' 改為'fastlane'
plugins_path = File.join(File.dirname(FILE), '.', 'Pluginfile')eval_gemfile(plugins_path) if File.exist?(plugins_path)
plugins_path = File.join(File.dirname(FILE), 'fastlane', 'Pluginfile') eval_gemfile(plugins_path) if File.exist?(plugins_path)


2.2.1 修改Fastfile文件(以下為部分示例,后面有完整demo。這種使用時(shí)在項(xiàng)目目錄下執(zhí)行fast lane即可)
desc "Push a new release build to the 蒲公英" lane :pgyAction do increment_build_number(xcodeproj: "XXXX")//這里是build版本號(hào)自增,防止小于等于之前build號(hào),這里需要打開Xcode-- build Setting --Versioning System --為Apple Generic (此處有坑,后面解釋) build_app(workspace: "項(xiàng)目名", scheme: "XXXX") # 插件 --- 蒲公英 # fastlane add_plugin pgyer 發(fā)布到蒲公英需要執(zhí)行這個(gè)命令安裝pgyer工具 # fastlane add_plugin firim 發(fā)布到firim需要執(zhí)行這個(gè)命令安裝firim工具 # fastlane add_plugin fastlane-plugin-version 安裝版本管理pgyer(api_key:"XXXX",
user_key:"XXXX")
這里的"XXX"可以使用.env里的環(huán)境變量替 換為 ENV['User_Key'] 注:User_Key環(huán)境變量
end
使用時(shí)在項(xiàng)目目錄下執(zhí)行fastlane 即可,選擇對(duì)應(yīng)操作
還有一種寫法外部傳入版本號(hào)和build參數(shù) (這種使用時(shí)需fastlane adhoc_pgy version:1.5 build:1
fastlane lane名稱 version: build:)
函數(shù)(一個(gè)方法)
desc "版本處理"
def setup_version_build(options)
increment_build_number(
build_number:options[:build])
increment_version_number(
version_number:options[:version])
end
desc "上線蒲公英"
lane :adhoc_pgy do |options|
setup_version_build(options)#調(diào)用上面函數(shù)
increment_build_number(xcodeproj: ENV['Xcodeproj'])#不需要執(zhí)行這行
build_app(
workspace: ENV['Workspace'],#指定workspace (使用cocopods)
scheme: ENV['Scheme'],#指定打的哪個(gè)scheme
silent: true,
clean: true,#打包前clean
output_directory: ENV['Pgy_Output_Path'],#輸出目錄
output_name: logDirectory,#輸出名字
export_xcargs: "-allowProvisioningUpdates",#允許自動(dòng)更新配置
export_method:"ad-hoc")#出包方法 app-store, ad-hoc, package, enterprise, development
pgyer(api_key: ENV['Api_Key'],
user_key: ENV['User_Key'])#ENV['XX']使用環(huán)境變量,看2.2.3
end
2.2.2修改Appfile文件(部分)
Appfile使用.env方式直接讀取變量即可 (看2.2.3)
app_identifier ENV['App_Identifier']
apple_id ENV['Apple_Id']
team_id ENV['Team_Id']
2.2.3 添加環(huán)境變量.env
在fastlane文件夾下創(chuàng)建添加.env 環(huán)境變量(touch .env )
例如:# 蒲公英 的api_key
Api_Key = "de1a6608cce966dee05a5df3c654113b"
蒲公英 的user_key
User_Key = "cd4b534a73e5bce41a9fa92b1fdc7b31"
2.2.4 添加發(fā)布到蒲公英和fir工具,如不需要可跳過
在項(xiàng)目中fastlane目錄下執(zhí)行
fastlane add_plugin pgyer 發(fā)布到蒲公英需要執(zhí)行這個(gè)命令安裝pgyer工具
fastlane add_plugin firim 發(fā)布到firim需要執(zhí)行這個(gè)命令安裝firim工具
安裝后生成Pluginfile


2.3以上要修改的地方修改好了(發(fā)布是否需要指定版本號(hào)和build)
1.不需要指定版本號(hào),使用build自增(不指定版本號(hào),使用時(shí)執(zhí)行fastlane命令)
increment_build_number(xcodeproj: ENV['Xcodeproj'])#修改Fastfile 需要執(zhí)行這行
2.指定版本號(hào)和build(使用時(shí)執(zhí)行fastlane + lane名 version:X build:X)例如fastlane adhoc_pgy version:1.5 build:1
setup_version_build(options)#調(diào)用函數(shù) #修改Fastfile 需要執(zhí)行這行


如出現(xiàn)Apple Generic Versioning is Not enabled ,需要打開Xcode-- build Setting --Versioning System --為Apple Generic 。如果已經(jīng)打開,還是報(bào)錯(cuò)。Xcode10的問題,需要在Xcode菜單欄選擇File-- Workspace Setting就會(huì)出現(xiàn)如下的界面,選擇Legacy Build即可

出現(xiàn)SuccessFully Exported 則導(dǎo)出ipa和dSYM成功

發(fā)布蒲公英成功如下圖:

是否需要自動(dòng)發(fā)布APP后臺(tái)截圖 和更新信息 備注等:配置有兩種方法
發(fā)布到appstore時(shí) 發(fā)現(xiàn)后臺(tái)的描述不見了或者被覆蓋了,需要在lane 里添加禁止使用元數(shù)據(jù)和截圖.不傳截圖和元數(shù)據(jù) skip_screenshots,skip_metadata設(shè)為true。要傳的話設(shè)為false 如下圖。(PS:可以配置多個(gè)參數(shù),需要可查看下面Deliver文件說明傳送門)
1.修改Fastfile文件pload_to_app_store 方法添加參數(shù)
pload_to_app_store(skip_screenshots: true,skip_metadata: true )
2.在fantlane文件夾下,修改Deliverfile 文件,如下圖(沒有的話在fantlane文件夾下執(zhí)行deliver init)
skip_screenshots(true)
skip_metadata(true)

如果需要手動(dòng)上傳元數(shù)據(jù)等,可以先更新下來,然后修改需要的txt文件。如下圖:截圖則放在screenshots下即可.發(fā)布時(shí)會(huì)彈出一個(gè)html文件預(yù)覽配置的信息(如下圖),終端會(huì)彈出Does the Preview on path './fastlane/Preview.html' look okay for you? 查看沒問題后y ,如果錯(cuò)了n ,然后修改。
從App Store Connect下載現(xiàn)有屏幕截圖
fastlane deliver download_screenshots
從App Store Connect下載現(xiàn)有元數(shù)據(jù)
fastlane deliver download_metadata



部分deliver參數(shù)
