前言
在項(xiàng)目測(cè)試階段,頻繁的打包發(fā)布會(huì)耗費(fèi)很多的時(shí)間。學(xué)習(xí)使用了Fastlane實(shí)現(xiàn)了自動(dòng)化打包發(fā)布到蒲公英&fir,以下內(nèi)容是實(shí)現(xiàn)的過程。
Fastlane安裝
Fastlane是一套使用Ruby寫的自動(dòng)化工具集,用于iOS和Android的自動(dòng)化打包、發(fā)布等工作,可以節(jié)省大量的時(shí)間。
安裝過程如下:
1.檢查Ruby版本,需要2.0及以上版本。在終端輸入以下命令確認(rèn):
ruby -v
需要注意的是需要將gem的source改為https://gems.ruby-china.org/。
如何檢查?在終端輸入以下命令:
gem sources
結(jié)果應(yīng)為:
*** CURRENT SOURCES ***
https://gems.ruby-china.org/
2.檢查Xcode命令行工具是否安裝。在終端輸入以下命令:
xcode-select --install
如果沒有安裝會(huì)進(jìn)行安裝。如果已經(jīng)安裝了則會(huì)提示:
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
3.安裝Fastlane
sudo gem install fastlane --verbose
如果出現(xiàn)以下錯(cuò)誤:
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/rougify
則輸入以下命令:
sudo gem install -n /usr/local/bin fastlane
4.檢查Fastlane是否正確安裝。輸入以下命令:
fastlane --version
可以看到我的Fastlane版本信息,我的是2.193.1。
Fastlane配置
1.打開終端,進(jìn)入你的項(xiàng)目工程的根目錄,輸入以下命令:
fastlane init
新版本安裝的時(shí)候會(huì)出現(xiàn)下面的分支,按要求選擇就行
(1)自動(dòng)截屏。這個(gè)功能能幫我們自動(dòng)截取APP中的截圖,并添加手機(jī)邊框(如果需要的話)
(2)自動(dòng)發(fā)布 beta 版本用于 TestFlight
(3)自動(dòng)發(fā)布到 AppStore
(4)手動(dòng)設(shè)置
目前我選擇的是4,按照提示, 多個(gè)Enter 后有可能會(huì)輸入開發(fā)者賬號(hào)和密碼。安裝成功之后,會(huì)在工程目錄生成一個(gè) fastlane 文件夾和 Appfile 和 Fastfile 兩個(gè)文件。Appfile保存蘋果開發(fā)者的相關(guān)信息、項(xiàng)目的相關(guān)信息等。Fastfile是運(yùn)行腳本。
2.蒲公英的Fastlane插件安裝
打開終端,進(jìn)入你的項(xiàng)目工程的根目錄,輸入以下命令:
fastlane add_plugin pgyer
出現(xiàn)
Plugin 'fastlane-plugin-pgyer' was added to './fastlane/Pluginfile'
It looks like fastlane plugins are not yet set up for this project.
fastlane will create a new Gemfile at path 'Gemfile'
This change is necessary for fastlane plugins to work
Should fastlane modify the Gemfile at path 'Gemfile' for you?
(y/n)
輸入y按回車,出現(xiàn)
Installing plugin dependencies...
Successfully installed plugins
便是安裝成功了。
3.編輯Fastfile文件
可參考我目前寫的一個(gè)簡(jiǎn)易的
注意:蒲公英的 api_key 和 user_key,開發(fā)者在自己賬號(hào)下的 賬號(hào)設(shè)置-API信息 中可以找到。因?yàn)槲覀兪瞧髽I(yè)證書,指定打包所使用的輸出方式所以選擇的enterprise,打其它類型的包的方法與enterprise類似,可自定義一個(gè)新的lane實(shí)現(xiàn)。
參考代碼如下
default_platform(:iOS)
scheme=“UBI”
api_key="填寫自己的"
user_key="填寫自己的"
platform :iOS do
desc "development ipa"
lane :development_build do|options|
gym(
output_name:"#{scheme}_#{get_build_number()}",
clean:true,
configuration:"Release",
export_method:"enterprise",
output_directory:"./fastlane/build",
)
puts "開始上傳蒲公英"
pgyer(api_key: "#{api_key}", user_key: "#{user_key}")
end
end
4.命令行打包
在終端輸入
fastlane development_build
便會(huì)進(jìn)行自動(dòng)打包并上傳蒲公英了,如果一切順利到此就結(jié)束了,如有遇到問題,可參考我期間遇到的問題
5.踩坑點(diǎn)
最后一步遇到了這樣一個(gè)問題,fastlane打包失敗profile和證書不匹配,如圖
原因:項(xiàng)目中的簽名選擇的是Automatic自動(dòng)找的profile文件和證書不匹配,改為手動(dòng)設(shè)置profile文件
打包上傳到fir的配置Fastlane配置
1.打開終端,進(jìn)入你的項(xiàng)目工程的根目錄,輸入以下命令:(同上)
fastlane init
2.蒲公英的Fastlane插件安裝
打開終端,進(jìn)入你的項(xiàng)目工程的根目錄,輸入以下命令:
fastlane add_plugin versioning
fastlane add_plugin firim
3.編輯Fastfile文件
可參考我目前寫的一個(gè)簡(jiǎn)易的
參考代碼如下
default_platform(:iOS)
scheme=“UBI”
platform :iOS do
desc "development ipa"
lane : to_firim do|options| #注意:后邊不可以有空格,不然會(huì)報(bào)錯(cuò)
gym(
output_name:"#{scheme}_#{get_build_number()}",
clean:true,
configuration:"Release",
export_method:"enterprise",
output_directory:"./firim",
)
puts "開始上傳fir"
firim(firim_api_token: "寫你自己的")
end
end
4.命令行打包
在終端輸入
fastlane to_firim
便會(huì)進(jìn)行自動(dòng)打包并上傳蒲公英了,如果一切順利到此就結(jié)束了
參考文章
安裝fastlane
踩坑點(diǎn)
iOS自動(dòng)化打包發(fā)布(Jenkins + Fastlane + GitLab + 蒲公英)
iOS開發(fā)之fastlane自動(dòng)化打包工具安裝和使用
fastlane 自動(dòng)打包到 fir.im 的踩坑之路