-
終端判斷是否安裝了ruby(參考文章講版本要大于2.0.0)
$ ruby -v
Snip20190702_1.png
-
檢查ruby源
-
這里需要說明一下, 我的mac之前配置Cocoapods時(shí),ruby源由默認(rèn)的https://rubygems.org/換成了https://gems.ruby-china.org/ 剛開始簡單的測試了下https://gems.ruby-china.org/找不到fastlane兽肤,因此這里需要將ruby源更換回來
-
查看ruby源
gem sources
Snip20190702_2.png-
如果需要更換ruby源
-
先移除當(dāng)前ruby源
gem sources --remove https://gems.ruby-china.org/
-
添加新的ruby源
gem sources -a https://rubygems.org/
-
再次查看ruby源 就更換為最新的了
gem sources
Snip20190702_3.png -
-
如果ruby版本過低 可以升級
-
gem update --system
-
確認(rèn)是否安裝了Xcode命令行工具
xcode-select --install
-
如果出現(xiàn)以下情況 則代表已經(jīng)安裝
Snip20190702_4.png -
若出現(xiàn)以下情況 點(diǎn)擊【安裝】就可
Snip20190702_5.png
-
-
安裝fastlane
gem install fastlane -NV
-
使用[gem install fastlane -NV]命令 若出現(xiàn)如下報(bào)錯(cuò):
You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.
更換以下命令
sudo gem install fastlane -NV -n /usr/local/bin
-
根據(jù)網(wǎng)絡(luò)狀況座掘,等待命令全部執(zhí)行完畢后 看到如下提示安裝成功
Snip20190702_6.png
-
-
配置fastlane
cd 項(xiàng)目目錄 fastlane init
-
終端框中會出現(xiàn)4種選項(xiàng) 這里我選擇的是4
-
參考說出現(xiàn)以下表明成功
屏幕快照 2019-07-02 21.01.50.png但是我等了好久 終端框沒見動(dòng)靜 關(guān)閉了終端框 然后重新打開終端框后仍輸入
fastlane init
終端框出現(xiàn)了如上所示圖片中內(nèi)容。
這時(shí)查看你的iOS工程可看到比原先多出了一些文件
-
屏幕快照 2019-07-02 21.06.16.png
-
打包上傳到蒲公英
-
安裝蒲公英插件
fastlane add_plugin pgyer
WechatIMG9.png等待幾分鐘后 輸入了兩次開機(jī)密碼后 提示成功
WechatIMG10.png-
修改Fastfile 內(nèi)容
-
打開自動(dòng)生成的Fastfile文件
-
vim ./fastlane/Fastfile
然后可以看到
WechatIMG6.png用文本編輯方式打開 并修改相應(yīng)內(nèi)容
-
# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
# https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
# https://docs.fastlane.tools/plugins/available-plugins
#
# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane
default_platform(:ios)
platform :ios do
desc "上傳蒲公英"
lane :TestPgyer do #TestPgyer 為lane 名稱,只要和后面的lane保持一致即可匠题,我們執(zhí)行時(shí)就是執(zhí)行這個(gè)方法
scheme_name = "xxx"
#導(dǎo)出路徑 我們可以桌面創(chuàng)建IPA_Info(沒有的話會自動(dòng)創(chuàng)建,名字可自定義) 文件夾來集中管理生成的ipa等文件
output_directory = "/Users/luckycodercai/Desktop/IPA_Info"
# add actions here: https://docs.fastlane.tools/actions
#導(dǎo)出名稱
output_name = "#{scheme_name}_#{Time.now.strftime('Pgyer%Y%m%d%H%M%S')}.ipa"
gym(
export_method: "development", #這里填寫導(dǎo)出方式 ad-hoc、enterprise缩功、app-store
#Xcode 9 默認(rèn)不允許訪問鑰匙串的內(nèi)容,必須要設(shè)置此項(xiàng)才可以
export_xcargs: "-allowProvisioningUpdates",
scheme: scheme_name,# target的名字
clean: true, # 在構(gòu)建前先clean
output_directory: output_directory, #ipa輸出目錄
output_name: scheme_name #ipa名字
)
# 上傳蒲公英,update_description為版本更新描述都办。
pgyer(api_key: "5d7f7f8f23cc9b636d19a2a7ab165xxx", user_key: "39b4763cb82f856c7d67af5b262e9xxx", update_description: "hello")
end
end
-
打包并自動(dòng)上傳 App 到蒲公英
//在項(xiàng)目目錄下執(zhí)行
fastlane TestPgyer #和前面lane后面的名稱保持一致
WechatIMG17.png
-
執(zhí)行結(jié)束后 桌面會生成output_directory定義的文件夾嫡锌,里面包含一個(gè)壓縮包和ipa包并且會自動(dòng)上傳到蒲公英
WechatIMG19.png
WechatIMG8.png
多target打包
target -> Edit Scheme -> 勾選Shared
可以點(diǎn)擊Manage Schemes 然后列表中查看或勾選相應(yīng)的scheme.
WechatIMG13.png
WechatIMG15.png
WechatIMG16.png
比如兩個(gè)target: 分別為xxx和xxxDev 則若要打包xxx,F(xiàn)astfile中的scheme_name = "xxx"若要打包 xxxDev 則Fastfile中的scheme_name修改為scheme_name = "xxxDev"
-
蒲公英有提供多種自動(dòng)化打包方式琳钉,其中使用 Fastlane 上傳 App 到蒲公英是種超級簡單的方式:
- 若工程中僅存在一個(gè)target势木,則生成的ipa包等直接存放于工程根目錄下,ipa也會自動(dòng)上傳到你設(shè)置的蒲公英賬號上歌懒。
- 若工程中存在多個(gè)target啦桌,需要按照上述對需要打包的target勾選Shared選項(xiàng),打包時(shí)及皂,終端會詢問你想打包哪個(gè)target甫男,生成的ipa包等直接存放于工程根目錄下,ipa包會自動(dòng)上傳到設(shè)置的蒲公英賬號上验烧。
打包并上傳到fir.im
與蒲公英操作基本一致:
-
安裝fir插件
fastlane add_plugin firim
WechatIMG28.png
中間輸入一次y和兩次開機(jī)密碼
提示Successfully installer plugins表示插件安裝成功
WechatIMG29.png
-
安裝官方工具fir-cli
gem install fir-cli
如果報(bào)如下圖權(quán)限錯(cuò)誤板驳,則更換命令:
sudo gem install -n /usr/local/bin fir-cli --no-ri --no-rdoc
WechatIMG30.png
提示如下圖 Successfully install xxx gems installed時(shí)表明安裝成功
WechatIMG31.png
-
修改Fastfile內(nèi)容
# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
# https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
# https://docs.fastlane.tools/plugins/available-plugins
#
# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane
default_platform(:ios)
platform :ios do
desc "上傳fir"
lane :TestFir do #TestFir 為lane 名稱,只要和后面的lane保持一致即可,我們執(zhí)行時(shí)就是執(zhí)行這個(gè)方法
scheme_name = "xxxDev"
#導(dǎo)出路徑 我們可以桌面創(chuàng)建xxxIPA(沒有的話會自動(dòng)創(chuàng)建) 文件夾來集中管理生成的ipa等文件
output_directory = "/Users/luckycodercai/Desktop/xxxIPA"
# add actions here: https://docs.fastlane.tools/actions
#導(dǎo)出名稱
output_name = "#{scheme_name}_#{Time.now.strftime('fir_im%Y%m%d%H%M%S')}.ipa"
gym(
export_method: "development", #這里填寫導(dǎo)出方式 ad-hoc碍拆、enterprise若治、app-store
#Xcode 9 默認(rèn)不允許訪問鑰匙串的內(nèi)容,必須要設(shè)置此項(xiàng)才可以
export_xcargs: "-allowProvisioningUpdates",
scheme: scheme_name,# target的名字
clean: true, # 在構(gòu)建前先clean
output_directory: output_directory, #ipa輸出目錄
output_name: scheme_name #ipa名字
)
# 上傳fir
firim(firim_api_token: "7844e5febf265cc35b5d47dfae43bxxx")
end
end
-
cd到工程目錄
打開到工程目錄
fastlane TestFir
WechatIMG32.png
WechatIMG33.png
WechatIMG34.png
- 執(zhí)行fastlane TestFir
遇到報(bào)錯(cuò):
Could not find action, lane or variable 'firim'. Check out the documentation for more details: https://docs.fastlane.tools/actions
使用命令:
sudo fastlane add_plugin firim
重新安裝fir插件
WechatIMG35.png
WechatIMG36.png
參考:
fastlane docs
iOS實(shí)現(xiàn)fastlane自動(dòng)化打包
官方工具 fir-cli 使用說明