官網(wǎng):https://docs.fastlane.tools
參考文章:https://www.raywenderlich.com/136168/fastlane-tutorial-getting-started-2
http://www.lxweimin.com/p/edcd8d9430f6
http://www.cocoachina.com/ios/20170519/19317.html?utm_source=tuicool&utm_medium=referral
注:
如果要使用最新版本,建議使用rvm來(lái)管理ruby
在使用sudo gem install fastlane命令安裝時(shí),如果報(bào)以下錯(cuò)誤
ERROR:? While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/xcodeproj
可以修改命令sudo gem install -n /usr/local/bin fastlane
如果fastlane加載緩慢,可以嘗試gem cleanup
fastlane工具:
除fastlane命令,你還可以訪問(wèn)以下fastlane工具
deliver: 上傳截圖, 元數(shù)據(jù), app應(yīng)用程序到App Store
supply: 上傳Android app應(yīng)用程序和元數(shù)據(jù)到Google Play
snapshot: 自動(dòng)捕獲iOS app應(yīng)用程序本地截圖
screengrab: 自動(dòng)捕獲Android app應(yīng)用程序本地截圖
frameit: 快速截屏并將截屏放入設(shè)備中
pem: 自動(dòng)生成和更新推送通知配置文件
sigh: 開(kāi)發(fā)證書(shū)和描述文件下載
produce: 使用命令行在iTunes Connect上創(chuàng)建新的app和開(kāi)發(fā)入口
cert: 自動(dòng)創(chuàng)建和配置iOS代碼簽名證書(shū)
spaceship: Ruby 庫(kù)訪問(wèn) Apple開(kāi)發(fā)者中心和 iTunes Connect
pilot: 最好的方式管理你的TestFlight 測(cè)試人員和從終端構(gòu)建
boarding: 最簡(jiǎn)單的方式邀請(qǐng)你的TestFlight beta測(cè)試人員
gym: iOS app打包簽名自動(dòng)化工具
match: 使用Git同步你的團(tuán)隊(duì)證書(shū)和配置文件
scan: 最簡(jiǎn)單方式測(cè)試你的 iOS 和 Mac apps
使用方式,以iOS為例:
cd 到項(xiàng)目根目錄
fastlane init
根據(jù)提示填寫(xiě)信息(有可能提示錯(cuò)誤)
然后會(huì)看到生成一個(gè)fastlane文件夾,文件夾中會(huì)有Appfile,F(xiàn)astfile等文件
Appfile
Appfile用來(lái)存放app_identifier,apple_id和team_id。 它的格式是這樣的:
app_identifier?"com.xxx.xxx"?#?app的bundle?identifier
apple_id?"xxx@xxx.com"?#?你的Apple?ID
team_id?"XXXXXXXXXX"?#?Team?ID
···
你也可以為每個(gè)lane(后面會(huì)講到)提供不同的 app_identifier, apple_id 和 team_id,例如:
app_identifier?"com.aaa.aaa"
apple_id?"aaa@aaa.com"
team_id?"AAAAAAAAAA"
for_lane?:inhouse?do
app_identifier?"com.bbb.bbb"
apple_id?"bbb@bbb.com"
team_id?"AAAAAAAAAA"
end
這里就是為Fastfile中定義的:inhouse設(shè)置單獨(dú)的信息。
Fastfile
Fastfile管理你所創(chuàng)建的 lane?。它的格式是這樣的:
···
#?自動(dòng)更新fastlane?工具
#?update_fastlane
#需要的fastlane的最小版本,在每次執(zhí)行之后會(huì)檢查是否有新版本,如果有會(huì)在最后末尾追加新版本提醒
fastlane_version?"2.30.1"
#默認(rèn)使用平臺(tái)是?ios,也就是說(shuō)文件可以定義多個(gè)平臺(tái)
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?"提交一個(gè)新的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?"部署一個(gè)新版本到App?Store"
lane?:release?do
#?match(type:?"appstore")
#?snapshot
gym(scheme:?"Docment")?#?Build?your?app?-?more?options?available
deliver(force:?true)
#?frameit
end
#?你可以定義自己的lane
#執(zhí)行l(wèi)ane成功后的回調(diào)
after_all?do?|lane|
#?slack(
#???message:?"Successfully?deployed?new?App?Update."
#?)
end
#?如果流程發(fā)生異常會(huì)走這里并終止
error?do?|lane,?exception|
#?slack(
#???message:?exception.message,
#???success:?false
#?)
end
end
我們也可以定義一個(gè)自己的lane:
desc?"企業(yè)版"
lane?:inHouse?do
gym(scheme:?"XXX",
export_method:"enterprise",
output_directory?"./build",?#?打包后的?ipa?文件存放的目錄
output_name?"XXX"??#?ipa?文件名
)
end
在調(diào)用fastlane 【管道】是后面可以傳遞參數(shù),一可以自定義action,參考http://www.lxweimin.com/p/538cabdf2193
比如可以在Fastfile中定義一個(gè)函數(shù)來(lái)處理接收到的參數(shù)
def prepare_version(options)
increment_version_number(
version_number:?options[:version]
)
increment_build_number(
build_number:?options[:build]
)
end
然后在某個(gè)lane中使用它
lane :appstore do |options|
···
prepare_version(options)
···
end
然后執(zhí)行這個(gè)lane的時(shí)候:
fastlane?appstore?version:2.4.0?build:2.0
另外,lane之間是可以相互調(diào)用的,就像函數(shù)間的調(diào)用一樣,比如在調(diào)用appstore的時(shí)候,可以在里面調(diào)用test的lane
lane :appstore
test
···
end
fastlane的基本使用就是這樣,在使用過(guò)程中,有幾個(gè)常用的action
gym:打包簽名自動(dòng)化工具,fastlane中包含了gym,詳情:https://fastlane.tools/gym,以前又個(gè)shenzhen的東西,gym是用來(lái)代替它的
你可以使用gym的action,但是每次需要傳遞參數(shù)
gym(scheme:"MyApp",workspace:"MyApp.xcworkspace")
也可以創(chuàng)建一個(gè)Gymfile來(lái)保存這些配置,新建一個(gè)Gymfile,使用命令fastlane gym init,這個(gè)文件中如何填寫(xiě),可以參考https://fastlane.tools/gym,https://docs.fastlane.tools/actions/
scheme"Example"
clean true?
output_directory"./build"#store the ipa in this folder
output_name"MyApp"#the name of the ipa file
export_options(
method:"app-store",
provisioningProfiles:{
"com.example.bundleid":"Provisioning Profile Name",
"com.example.bundleid2":"Provisioning Profile Name 2"?
}
)
當(dāng)然也可以使用自定義action的方式,來(lái)提供默認(rèn)gym配置,自定義action,參考http://www.lxweimin.com/p/538cabdf2193