前言
每位iOS開發工程師都不可避免項目打包的時候,有時候繁瑣的打包即費事又費力,尤其是在大量測試下更是不可避免。這時有了許多的分布平臺和快捷打包工具就大大提高了我們的效率。
蒲公英
蒲公英是國內領先的應用內測分發平臺,我們可以打包應用到這個平臺,進行分布式測試,而且該平臺支持Jenkins和fastlane。
fastlane
fastlane是使用Ruby語言寫的,支持iOS和安卓的打包、分發平臺、上傳應用到商店的工具。
fastlane安裝過程
以下過程都在Mac終端上進行
1.建議更新gem?
sudo gem update --system
需要輸入用戶密碼
2.檢查gem源
gem sources
結果應為
*** CURRENT SOURCES ***
https://gems.ruby-china.org/
如果是,忽略2.1和2.2步驟
2.1如果不是,移除你的源
sources --remove https://rubygems.org/
https://rubygems.org/指的gem sources顯示的源
2.2添加國內的源
gem sources -a https://gems.ruby-china.org/
3.安裝Xcode命令行工具
xcode-select --install
如果提示以下,就是安裝過了,無需重新安裝
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
4.安裝fastlane
sudo gem install -n /usr/local/bin fastlane
5.安裝完成后可檢測下fastlane版本
fastlane --version
我的版本是2.66.2
/Library/Ruby/Gems/2.3.0/gems/fastlane-2.66.2/bin/fastlane
-----------------------------
fastlane 2.66.2
到現在,我們安裝fastlane的到此告一段落了。
蒲公英使用
注冊過程就不多說啦
點擊我的應用 -> ?添加空白應用 -> 填上應用名稱和包名 -> 添加應用
成功后點擊API,記下API Key 和?User Key 之后會用到的
fastlane 使用
1.終端cd到項目根目錄,這里我推薦一個小工具Go2Shell。 點擊它打開終端直達所在目錄:
2.初始化fastlane
fastlane init
走的過程會提示你輸入項目開發者的AppleID和密碼
Your Apple ID (e.g. fastlane@krausefx.com):
確認項目信息,有誤按n手動修改
+----------------+--------------------------------------+
| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Detected Values ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|
+----------------+--------------------------------------+
| Apple ID ? ? ? ? ? ?| xxxxx@xxxxx.com ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |?
| App Name ? ? ? | FastlaneDemo ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?|
| App Identifier ?| com.xxxxxx.FastlaneDemo ? ? ? ? ? ? ? ? ? ? ? |
| Workspace ? ? ?| /Users/xxxxxxx/Desktop/FastlaneDemo |
| ? ? ? ? ? ? ? ? ? ? ? ? ?| /FastlaneDemo.xcworkspace ? ? ? ? ? ? ? ? ? ?|
+----------------+--------------------------------------+
這一步是上架App Store用的,可以上信息和效果圖那些,我這邊填了n
[14:26:33]: Do you want to setup 'deliver', which is used to upload appscreenshots, app metadata and app updates to the App Store? This requires the app tobe in the App Store already (y/n)
成功之后項目多了個fastlane文件夾
3.配置Fastfile
打開fastlane/Fastfile,找到?lane :beta do … ?end,內容改為
lane :beta do
????#scheme選擇方案
????gym(scheme: "FastlaneDemo”,
????#output_name 打包的ipa的名字
????output_name: "APPName_AD”,
????#export_method 打包模式
? ? export_method: "ad-hoc”,
????#分別是app-store、ad-hoc、development、enterprise
????????export_options: {
????????provisioningProfiles: {
????????????#"bundle id" => "項目描述文件"
????????????"com.xxxx.FastlaneDemo" => "FastlaneDemoAD"
????????????}
????????})
????#api_key和user_key就是之前蒲公英保存的
????pgyer(api_key: "b9cbebxxxxxxxxxxxxxxxxxxx7de3dd6", user_key: "b9cbebxxxxxxxxxxxxxxxxxxx7de3dd6")?
end
4.添加蒲公英fastlane插件,cd到項目根目錄
fastlane add_plugin pgyer
5.如果項目有pod的,在線根目錄Gemfile文件加上
gem 'cocoapods'
然后終端cd跟目錄操作
gym init
6.開始分發到蒲公英
bundle exec fastlane beta
7.成功提示
fastlane.tools just saved you 6 minutes! ??
這時,可以去蒲公英看看你的應用了,以后分發只需終端根目錄執行bundle exec fastlane beta即可。
注意事項
如果gym 和 bundler版本過舊,可以試試更新一下。
sudo gem install -n /usr/local/bin gym?
sudo gem install -n /usr/local/bin?bundler?
如果沒有開發者私鑰也會失敗,需添加私鑰
打包失敗時先試試用xcode打包有沒有問題,在排除證書問題。
Ad-Hoc證書需自己在developer.apple.com上手動生成。
喜歡的點記得小心心哦~