一 自動(dòng)化打包工具-Fastlane
- Fastlane是一套使用Ruby寫(xiě)的自動(dòng)化工具集,旨在簡(jiǎn)化Android和iOS的部署過(guò)程生均,自動(dòng)化你的工作流奢浑。它可以簡(jiǎn)化一些乏味琼掠、單調(diào)、重復(fù)的工作窍侧,像截圖县踢、代碼簽名以及發(fā)布App
-
fastlane工具集
-
gym 是fastlane提供的打包工具
- 在很多地方還可以看到別名build_app build_ios_app其實(shí)都是使用的是gym
- testflight 上傳ipa到App store connect
- deliver 上傳屏幕截圖沙绝、元數(shù)據(jù)嘱腥、ipa文件到App store connect
-
gym 是fastlane提供的打包工具
官方文檔地址 https://docs.fastlane.tools
-
使用 bundler 管理依賴(lài)
bundler用來(lái)管理fastlane版本和fastlane運(yùn)行時(shí)的相關(guān)依賴(lài)版本,相當(dāng)于iOS開(kāi)發(fā)中的CocoaPods框架谤牡,兩者命令也很相似
-
安裝bundler
sudo gem install bundler
-
在項(xiàng)目根目錄輸入
bundle init
生成Gemfile文件锋爪,在此文件寫(xiě)入source "https://gems.ruby-china.com" gem "fastlane" gem "cocoapods"
- 安裝依賴(lài)庫(kù)丙曙,生成Gemfile.lock文件爸业,類(lèi)似于Podfile.lock文件功能, 配置Jenkins腳本是第一步操作也是調(diào)用該命令
bundle install
- 更新Gemfile.lock文件的版本和依賴(lài)
bundle update
-
fastlane 安裝
- 安裝最新的Xcode命令行工具
xcode-select --install
- 使用HomeBrew
brew cask install fastlane
- 使用RubyGems
sudo gem install fastlane - NV
-
初始化Fastlane
- cd 工程目錄執(zhí)行
fastlane init
- 使用swift
fastlane init swift
-
出現(xiàn)下圖 選擇你所需要的功能模板
WeChatcd353a25e83e0c56b7a41aa8c41acf5c.png
1.自動(dòng)化截圖 2.自動(dòng)化beta分發(fā)至TestFlight 3.自動(dòng)化App Store 分發(fā) 4.手動(dòng)寫(xiě)自動(dòng)化腳本
-
我選擇第四個(gè)模板亏镰,將生成fastlane文件夾扯旷,下面將生成兩個(gè)文件 Appfile Fastfile
-
Appfile - 用來(lái)配置app_identifier app_id team_id信息
app_identifier "xxxxxxxx" # App的bundle identifier apple_id("xxxx@xx.com") # 你的Apple ID itc_team_id "xxxxxxx" # App Store Connect Team ID team_id("xxxx") # Developer Portal Team ID
Fastfile - 配置自動(dòng)化腳本
default_platform(:ios) platform :ios do desc "Description of what the lane does" workspace = "xxxx.xcworkspace" scheme = "xxxx" bundleid = "xxxxxxx" currentTime = Time.new.strftime("%Y-%m-%d %H-%M-%S") ipa_name = "xxxx" output_path = "../#{ipa_name} #{currentTime}" ipa_path = "#{output_path}/#{ipa_name}.ipa" # 蒲公英 api_key user_key pgyer_api_key = "xxxxxxx" payer_user_key = "xxxxxxx" # firim api_token firim_api_token = "xxxxxxxx" # bugly app_id app_key bugly_app_id = "xxxxxxx" bugly_app_key = "xxxxxxx" # crashlytics api_token build_secret crashlytics_api_token = "xxxxxxx" crashlytics_build_secret = "xxxxxxxx" before_all do |lane, options| cocoapods end lane :dev do |options| build_ios_app( clean:true, workspace: "#{workspace}", output_directory: "#{output_path}", output_name: "#{ipa_name}", scheme: "#{scheme}", configuration: "Debug", export_method: "development", export_options: { provisioningProfiles: { "#{bundleid}" => "Provisioning Profile Name", } }, export_xcargs: "-allowProvisioningUpdates" ) pgyer(api_key: "#{pgyer_api_key}", user_key: "#{payer_user_key}") firim(firim_api_token: "#{firim_api_token}") # 上傳dSYM到Bugly upload_app_to_bugly( file_path: "#{ipa_path}", app_key: "#{bugly_app_key}", app_id: "#{bugly_app_id}", pid: "2", #應(yīng)用平臺(tái)標(biāo)識(shí), 用于區(qū)分產(chǎn)品平臺(tái) android:1 iOS:2 download_limit: 999 ) #上傳dSYM到crashlytics crashlytics( api_token: "069c7f2852fe97ae2b9572f799200a2ae1da3621", build_secret: "0cb5ed2e8ff4ed31a5b03093e96fcbc3b81ade7021295e2a2e0afe35661c5d3b" ) end lane :adhoc do |options| build_ios_app( clean: true, workspace: "#{workspace}", output_directory: "#{output_path}", output_name: "#{ipa_name}", scheme: "#{scheme}", configuration: "Debug", export_method: "ad-hoc", export_options: { provisioningProfiles: { "#{bundleid}" => "Provisioning Profile Name", } }, export_xcargs: "-allowProvisioningUpdates" ) pgyer(api_key: "#{pgyer_api_key}", user_key: "#{payer_user_key}") firim(firim_api_token: "#{firim_api_token}") # 上傳dSYM到Bugly upload_app_to_bugl( file_path: "#{ipa_path}", app_key: "#{bugly_app_key}", app_id: "#{bugly_app_id}", pid: "2", #應(yīng)用平臺(tái)標(biāo)識(shí), 用于區(qū)分產(chǎn)品平臺(tái) android:1 iOS:2 download_limit: 999 ) #上傳dSYM到crashlytics crashlytics( api_token: "#{crashlytics_api_token}", build_secret: "#{crashlytics_build_secret}" ) end lane :app_store do |options| build_ios_app( clean: true, workspace: "#{workspace}", output_directory: "#{output_path}", output_name: "#{ipa_name}", scheme: "#{scheme}", export_method: "app-store", export_options: { provisioningProfiles: { "#{bundleid}" => "Provisioning Profile Name", } }, export_xcargs: "-allowProvisioningUpdates" ) # 上傳dSYM到Bugly upload_app_to_bugl( file_path: "#{ipa_path}", app_key: "#{bugly_app_key}", app_id: "#{bugly_app_id}", pid: "2", #應(yīng)用平臺(tái)標(biāo)識(shí), 用于區(qū)分產(chǎn)品平臺(tái) android:1 iOS:2 download_limit: 999 ) #上傳dSYM到crashlytics crashlytics( api_token: "#{crashlytics_api_token}", build_secret: "#{crashlytics_build_secret}" ) #可以上傳屏幕截圖、元數(shù)據(jù)索抓、二進(jìn)制文件到App sotre Connect deliver( submit_for_review: true, automatic_release: false, force: true, skip_metadata: true, skip_screenshots: true, ) end
- 下面相當(dāng)于打包前執(zhí)行一次pod install 命令
before_all do |lane, options| cocoapods end
- build_ios_app 打包編譯 下面命令是訪問(wèn)鑰匙串 找到對(duì)應(yīng)證書(shū)
export_xcargs: "-allowProvisioningUpdates
-
app內(nèi)側(cè)分發(fā)平臺(tái) pgyer-蒲公英 firim-fir.im
# 安裝插件 fastlane add_plugin pgyer fastlane add_plugin firim # 調(diào)用插件 pgyer(api_key: "#{pgyer_api_key}", user_key: "#{payer_user_key}") firim(firim_api_token: "#{firim_api_token}")
crashlytics 崩潰日志分析
crashlytics(api_token: "#{crashlytics_api_token}", build_secret: "#{crashlytics_build_secret}")
-
Bugly 騰訊-崩潰日志分析
-
fastlane沒(méi)有基于Bugly的插件或者action,需要手動(dòng)創(chuàng)建action,之前Bugly官網(wǎng)有安裝教程钧忽,后來(lái)不知道為什么沒(méi)有了,但是在github上的我們還是可以找到此action https://github.com/BuglyDevTeam/Bugly-FastlanePlugin逼肯,
WeChat8be1a230aeba828a0bc4ec3b7cb00656.png 解壓后看到有兩個(gè)文件 update_app_to_bugly.rb upload_app_to_bugly.rb 我們要用到的就是upload_app_to_bugly.rb
-
終端輸入下面命令
fastlane new_action
WeChatbe14716d4f6ad05718344fc19c448458.png這里action名稱(chēng)輸入 upload_app_to_bugly 找到剛才下載的rb文件到fastlane/actions路徑下替換下此文件
upload_app_to_bugly( file_path: "#{ipa_path}", app_key: "#{bugly_app_key}", app_id: "#{bugly_app_id}", pid: "2", #應(yīng)用平臺(tái)標(biāo)識(shí), 用于區(qū)分產(chǎn)品平臺(tái) android:1 iOS:2 download_limit: 999 )
-
-
deliver - 將截圖耸黑,元數(shù)據(jù)和二進(jìn)制文件上傳到App Store Connect
fastlane deliver init # deliver初始化
-
-
然后可以按照自己的需求選擇是否上傳截圖、元數(shù)據(jù)篮幢、二進(jìn)制文件上傳大刊。下面是我項(xiàng)目中的配置,更多詳細(xì)操作- https://docs.fastlane.tools/actions/upload_to_app_store/
```
deliver(
submit_for_review: true,
automatic_release: false,
force: true,
skip_metadata: true,
skip_screenshots: true,
)
```
- fastlane 基本配置完成可以完成自動(dòng)化打包操作
```
fastlane dev # 開(kāi)發(fā)時(shí)打包
fastlane adhoc # 內(nèi)測(cè)打包
fastlane appstore # 上線(xiàn)打包
```
----
二 持續(xù)化集成工具——Jenkins
- Jenkins是一個(gè)開(kāi)源項(xiàng)目三椿,提供了一種易于使用的持續(xù)集成系統(tǒng)缺菌,使開(kāi)發(fā)者從繁雜的集成中解脫出來(lái),專(zhuān)注于更為重要的業(yè)務(wù)邏輯實(shí)現(xiàn)上.
-
homebrew 是 Mac 下的一個(gè)包管理工具搜锰,可以很方便地進(jìn)行安裝/卸載/更新各種軟件包伴郁,可以用來(lái)快速搭建各種本地環(huán)境。homebrew 安裝
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
-
Jenkins是基于java的開(kāi)源項(xiàng)目蛋叼,所以需要配置java環(huán)境變量
brew cask install java
-
安裝Jenkins推薦通過(guò)homebrew安裝
brew install jenkins
建議按照上面的方式安裝Jenkins,會(huì)官網(wǎng)下載pkg安裝包安裝焊傅,會(huì)創(chuàng)建一個(gè)Jenkins的用戶(hù)
-
啟動(dòng) Jenkins
jenkins
-
腳本方式開(kāi)始啟動(dòng)Jenkins
命令行安裝的Jenkins每次重啟后需要到終端執(zhí)行上面的啟動(dòng)命令,使用以下步驟在重啟時(shí)自動(dòng)執(zhí)行Jenkins啟動(dòng)命令系統(tǒng)當(dāng)前用戶(hù)下創(chuàng)建啟動(dòng)腳本文件 jenkinsBoot.sh
-
加入上面啟動(dòng)jenkins命令
WeChat32b86befd45919f29111c3a3fae4bea8.png -
設(shè)置腳本文件打開(kāi)方式——終端(iTerm)
WeChat589f4a43a10172df5f0f180e2265f040.png -
加入用戶(hù)登錄項(xiàng)
- 點(diǎn)擊設(shè)置 -> 用戶(hù)與群組 -> 找到當(dāng)前用戶(hù) WeChat2121a359971ad9522a866d28046c7390.png
- 點(diǎn)擊設(shè)置 -> 用戶(hù)與群組 -> 找到當(dāng)前用戶(hù)
重啟計(jì)算機(jī)鸦列,會(huì)自動(dòng)執(zhí)行jenkins.sh腳本
-
在瀏覽器中輸入 http://localhost:8080 出現(xiàn)重設(shè)初始密碼的界面 (默認(rèn)端口8080)
WeChatebdb8416b310a461df1c3ea2a89d03b7.png
-
注冊(cè)用戶(hù)完成開(kāi)始jenkins持續(xù)集成
Jenkins插件管理
點(diǎn)擊系統(tǒng)管理->插件管理, 可以安裝租冠、更新、卸載jenkins插件
- Gitlab插件: GitLab Plugin
- 簽名證書(shū)管理插件:Credentials Plugin 和 Keychains and Provisioning Profiles Management
- 獲取倉(cāng)庫(kù)提交的commit log:Git Changelog Plugin
- 自定義全局變量:Environment Injector Plugin
- Jenkins內(nèi)部顯示生成的屏幕截圖 HTML Publisher Plugin
- fastlane工具的彩色輸出:AnsiColor Plugin
- 插件將為您節(jié)省大量時(shí)間: Rebuild Plugin
環(huán)境變量
點(diǎn)擊系統(tǒng)管理->系統(tǒng)設(shè)置 找到全局屬性薯嗤,勾選環(huán)境變量顽爹,增加一堆鍵值對(duì):
- LANG = zh_CN.UTF-8
- PATH = (終端中執(zhí)行 echo $PATH 命令的輸出,為一堆路徑)
新建任務(wù)
點(diǎn)擊新建任務(wù)
項(xiàng)目初始化配置骆姐,下面是我的配置
-
源碼管理
我使用的是Gitlab镜粤,需要添加Credentials 點(diǎn)擊憑據(jù)
WeChatdf9e0bde23c709696104aec135f4969b.png- Username: 自己設(shè)置,到時(shí)候配置源碼時(shí)需要用到
- Private Key -> Enter ditectly -> key 輸入ssh的私鑰
- Passphrase: 配置ssh的時(shí)有密碼就輸入
構(gòu)建
點(diǎn)擊增加構(gòu)建步驟玻褪,選擇執(zhí)行 shell,輸入下面命令:
export LC_ALL=en_US.UTF-8 export LANG=en_US.UTF-8 bundle update fastlane bundle exec fastlane $export_method
上面這幾行命令就是執(zhí)行fastlane的自動(dòng)化打包操作H饪省!带射!
點(diǎn)擊構(gòu)建 同规,Jenkins+Fastlane打愉快的開(kāi)始!!券勺!