有的公司分工比較細(xì)护姆,諸如項(xiàng)目打包矾端、發(fā)布這些工作,都會有專門的測試人員去負(fù)責(zé)卵皂,這就為開發(fā)人員省去了大部分時間秩铆。當(dāng)然,當(dāng)你看到這篇文章時灯变,就證明你所在的公司并不是這樣殴玛。
不過不要擔(dān)心,既然你找到了我添祸,我就將Fastlane的使用技巧傳授給你族阅。
Fastlane是麻省理工學(xué)院批準(zhǔn)的開源項(xiàng)目,可以將Mac膝捞、iOS坦刀、android項(xiàng)目的自動打包、發(fā)布等一系列繁瑣的任務(wù)自動化蔬咬。
Fastlane安裝
-
打開終端輸入xcode-select --install鲤遥,若提示如下圖,則說明已經(jīng)安裝了Xcode命令行工具林艘;否則會彈出對話框盖奈,選擇安裝即可。
- 輸入ruby -v查看ruby版本狐援,要求2.0及以上版本钢坦。可以通過gem管理ruby版本啥酱,這里需要注意的是爹凹,ruby的鏡像文件路徑已經(jīng)改為https://gems.ruby-china.org/
-
輸入sudo gem install fastlane -NV ,通過gem安轉(zhuǎn)fastlane镶殷。最近因?yàn)閄code 9的問題禾酱,升級了fastlane。
Fastlane配置
- 打開終端绘趋,切換目錄到包含xxx.xcodeproj的項(xiàng)目目錄下輸入fastlane init颤陶,期間會讓輸入Apple ID(開發(fā)者賬號)及app_identifier等信息,可以根據(jù)需要自行選擇填寫陷遮。最后會在當(dāng)前目錄下生成fastlane文件夾滓走。
-
進(jìn)入fastlane文件夾,打開Appfile文件帽馋,里面是剛剛填寫的一些信息搅方∫咧啵可以在里面配置多個app_identifier、apple_id信息腰懂。
- 打開Fastfile文件梗逮,里面便是自動生成的fastlane使用方法,當(dāng)然绣溜,需要根據(jù)需要進(jìn)行修改慷彤。
在編寫fastfile文件之前,需要說明一下怖喻,F(xiàn)astlane著實(shí)太強(qiáng)大底哗,因此本文只介紹其中的一種方法:本機(jī)已經(jīng)安裝Signing Certificate及其對應(yīng)的Provisioning Profile,也就是說打開Xcode锚沸,將Automatically manage signing選項(xiàng)去掉跋选,手動進(jìn)行選擇,且能編譯運(yùn)行哗蜈。
Fastfile文件的編寫
-
App Store版本
# You can define as many lanes as you want
desc "Deploy a new version to the App Store"
lane :release do |op|
increment_version_number(version_number: op[:version]) #根據(jù)入?yún)ersion獲取app版本號
increment_build_number(build_number: op[:version]) #將build號設(shè)置與app版本號相同# 設(shè)置app的info.plist文件項(xiàng) set_info_plist_value(path: "./xxx/Info.plist", #info.plist文件目錄 key: "UIFileSharingEnabled", # key前标,將plist文件以Source Code形式打開可查詢對應(yīng)的key value: false) # value # 設(shè)置自定義plist文件項(xiàng),用于給app配置不同的服務(wù)器URL set_info_plist_value(path: "./xxx/hostAddress.plist", key: "host", value: "https:/zhengshiServer:xx/xxx/xxx") # 設(shè)置某些服務(wù)是否有效 # 還可以使用modify_services距潘,具體參考官網(wǎng)相關(guān)文檔 produce( enable_services:{ push_notification: "on", } ) # 更新Provisioning Profile # 在項(xiàng)目當(dāng)前目錄下創(chuàng)建provisions文件夾炼列,并將App Store版本的.mobileprovision文件保存在里面,名稱隨意音比。 update_project_provisioning(profile: "./provisions/appstore.mobileprovision") # 更新項(xiàng)目團(tuán)隊(duì) update_project_team(path: "xxx.xcodeproj", teamid: "5JC8GZ432G") # 開始打包 gym(# use_legacy_build_api: true, # Xcode 9之后俭尖,需要去掉 output_name: "appstore", # 輸出的ipa名稱 silent: true, # 隱藏沒有必要的信息 clean: true, # 在構(gòu)建前先clean configuration: "Release", # 配置為Release版本 codesigning_identity: "iPhone Distribution: xxx Co.,Ltd. (5JC8GZ432G)", # 代碼簽名證書 buildlog_path: "./fastlanelog", # fastlane構(gòu)建ipa的日志輸出目錄 export_method: "app-store", # Xcode 9增加export_method標(biāo)簽 output_directory: "/Users/xxx/Desktop") # ipa輸出目錄 end
-
Development版本
desc "Build a new version use the ceshi"
lane :ceshi do |op|
increment_version_number(version_number: op[:version])
increment_build_number(build_number: op[:version])set_info_plist_value(path: "./xxx/Info.plist", key: "UIFileSharingEnabled", value: true) set_info_plist_value(path: "./xxx/hostAddress.plist", key: "host", value: "https:/ceshiServer:xx/xxx/xxx") # 設(shè)置某些服務(wù)是否有效 # 還可以使用modify_services,具體參考官網(wǎng)相關(guān)文檔 produce( enable_services:{ push_notification: "off", } ) # 將Development版本的.mobileprovision文件保存在里面洞翩,名稱隨意稽犁。 update_project_provisioning(profile: "./provisions/development.mobileprovision") update_project_team(path: "xxx.xcodeproj", teamid: "5JC8GZ432G") gym(# use_legacy_build_api: true, output_name: "ceshi", silent: true, clean: true, configuration: "Debug", buildlog_path: "./fastlanelog", codesigning_identity: "iPhone Developer: xxx (xxxxxxxxxx)", export_method: "development", # Xcode 9增加export_method標(biāo)簽 output_directory: "/Users/xxx/Desktop" ) end
-
其他版本類似,此處不在給出骚亿。其中export_method標(biāo)簽對應(yīng)的值有:
- export_method: "development"
- export_method: "enterprise"
- export_method: "app-store"
批量處理
desc "build all version ipa"
lane :all do |op|
t = op[:version]
ceshi version:t
release version:t
end
Fastlane使用
最后已亥,只需在終端(相關(guān)項(xiàng)目目錄下)輕輕敲入:
fastlane ceshi version:1.0.0 // 打包c(diǎn)eshi環(huán)境ipa,app版本號為1.0.0
fastlane release version:1.0.0 // 打包App Store版本ipa循未,app版本號為1.0.0
fastlane all version:1.0.0 // 打包c(diǎn)eshi陷猫、App Store版本ipa秫舌,app版本號為1.0.0
我們便可以去喝咖啡了的妖,執(zhí)行打包過程就交給fastlane去完成,是不是很爽足陨?
Fastlane還有很多的功能供大家使用嫂粟,比如match(能夠使團(tuán)隊(duì)通過git同步證書和配置文件)、sigh(生成配置文件)零抬、snapshot(生成截圖)以及git的一些相關(guān)操作等等平夜。大家可以到GitHub或者官網(wǎng)進(jìn)行相關(guān)知識的學(xué)習(xí)。
授人以魚不如授人以漁卸亮,傳送門獻(xiàn)上:
GitHub_Fastlane工具文檔
Fastlane官網(wǎng)
關(guān)注微信公眾號CodingArtist忽妒,可以第一時間得到文章更新通知! _