使用fastlane自動化打包測試發(fā)布

官網(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來管理ruby

在使用sudo gem install fastlane命令安裝時,如果報以下錯誤

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命令,你還可以訪問以下fastlane工具

deliver: 上傳截圖, 元數(shù)據(jù), app應用程序到App Store

supply: 上傳Android app應用程序和元數(shù)據(jù)到Google Play

snapshot: 自動捕獲iOS app應用程序本地截圖

screengrab: 自動捕獲Android app應用程序本地截圖

frameit: 快速截屏并將截屏放入設備中

pem: 自動生成和更新推送通知配置文件

sigh: 開發(fā)證書和描述文件下載

produce: 使用命令行在iTunes Connect上創(chuàng)建新的app和開發(fā)入口

cert: 自動創(chuàng)建和配置iOS代碼簽名證書

spaceship: Ruby 庫訪問 Apple開發(fā)者中心和 iTunes Connect

pilot: 最好的方式管理你的TestFlight 測試人員和從終端構(gòu)建

boarding: 最簡單的方式邀請你的TestFlight beta測試人員

gym: iOS app打包簽名自動化工具

match: 使用Git同步你的團隊證書和配置文件

scan: 最簡單方式測試你的 iOS 和 Mac apps


使用方式,以iOS為例:

cd 到項目根目錄

fastlane init

根據(jù)提示填寫信息(有可能提示錯誤)

然后會看到生成一個fastlane文件夾,文件夾中會有Appfile,F(xiàn)astfile等文件

Appfile

Appfile用來存放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

···

你也可以為每個lane(后面會講到)提供不同的 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設置單獨的信息。

Fastfile

Fastfile管理你所創(chuàng)建的 lane?。它的格式是這樣的:

···

#?自動更新fastlane?工具

#?update_fastlane

#需要的fastlane的最小版本,在每次執(zhí)行之后會檢查是否有新版本,如果有會在最后末尾追加新版本提醒

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

#執(zhí)行l(wèi)ane成功后的回調(diào)

after_all?do?|lane|

#?slack(

#???message:?"Successfully?deployed?new?App?Update."

#?)

end

#?如果流程發(fā)生異常會走這里并終止

error?do?|lane,?exception|

#?slack(

#???message:?exception.message,

#???success:?false

#?)

end

end

我們也可以定義一個自己的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中定義一個函數(shù)來處理接收到的參數(shù)

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

然后執(zhí)行這個lane的時候:

fastlane?appstore?version:2.4.0?build:2.0


另外,lane之間是可以相互調(diào)用的,就像函數(shù)間的調(diào)用一樣,比如在調(diào)用appstore的時候,可以在里面調(diào)用test的lane

lane :appstore

test

···

end


fastlane的基本使用就是這樣,在使用過程中,有幾個常用的action

gym:打包簽名自動化工具,fastlane中包含了gym,詳情:https://fastlane.tools/gym,以前又個shenzhen的東西,gym是用來代替它的

你可以使用gym的action,但是每次需要傳遞參數(shù)

gym(scheme:"MyApp",workspace:"MyApp.xcworkspace")

也可以創(chuàng)建一個Gymfile來保存這些配置,新建一個Gymfile,使用命令fastlane gym init,這個文件中如何填寫,可以參考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"?

}

)

當然也可以使用自定義action的方式,來提供默認gym配置,自定義action,參考http://www.lxweimin.com/p/538cabdf2193

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內(nèi)容