最近好多微信文章都推薦fastlane,自己也總結(jié)一下我使用fastlane的過程吧。
其實自動化打包的工具有很多,比較流行的有Jenkins
和fastlane
,原來使用Jenkins
,感覺這個工具比較麻煩,需要配置的東西非常多,還需要倉庫地址等等很多信息,然而fastlane
是比較簡單快速的,(ios,Android都支持),github地址:
https://github.com/fastlane/fastlane 文檔地址:https://docs.fastlane.tools/
github上有 24014多星星。3659個fork,所以大量的開發(fā)者信任并一起維護他。
安裝前的準備工作
1、首先確認是否安裝了ruby,終端查看下ruby版本
使用命令ruby -v
2、確認是否安裝了Xcode命令行工具
使用命令
xcode-select --install
如果是圖中的情況是安裝成功
如果出現(xiàn):
就點擊安裝就行了。。。
開始正式安裝fastlane
1、安裝fastlane(兩種方式都可以)
# Using RubyGems
sudo gem install fastlane -NV
或者
# Alternatively using Homebrew
brew cask install fastlane
個人操作
執(zhí)行命令sudo gem install fastlane -NV
錯誤原因:應該是
https://gems.ruby-china.org/
沒有找到包,我們可以嘗試訪問這個地址:https://gems.ruby-china.org/出現(xiàn)這個界面
也就是我們需要更換源了
1、查看源:
gem sources
2、刪除源:
gem sources --remove https://gems.ruby-china.org/
3、更換源:
gem sources -a https://gems.ruby-china.com
具體步驟:
繼續(xù)安裝,執(zhí)行命令sudo gem install fastlane -NV
2、使用
1、打開終端,cd 到你的項目下
命令: cd + 項目目錄
2、執(zhí)行fastlane命令 fastlane init
如圖
下面會有四個選項供你選擇
- 自動截屏。幫我們自動截取APP中的截圖
- 自動發(fā)布beta版本用于TestFlight
- 自動發(fā)布到AppStore
- 手動設置
選擇4 ,會出現(xiàn)如圖的操作
一直按enter鍵就可以了
如圖就成功了
配置
我們項目下fastlane
有兩個文件Appfile
和Fastfile
Appfile
文件
# app_identifier("[[APP_IDENTIFIER]]") # The bundle identifier of your app
# apple_id("[[APPLE_ID]]") # Your Apple email address
# For more information about the Appfile, see:
# https://docs.fastlane.tools/advanced/#appfile
app_identifier
用于指定APP的bundle id
,apple_id
指的是你的AppleID
Fastfile
文件
# 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 "Description of what the lane does"
lane :custom_lane do
# add actions here: https://docs.fastlane.tools/actions
end
end
lane :custom_lane do
中的custom_lane
是函數(shù)的名稱,打包執(zhí)行命令的時候使用。
# add actions here: https://docs.fastlane.tools/actions
這塊就是讓我們加具體執(zhí)行的插件、命令等操作用于打包。
簡單打包用于測試,可打包成ad-hoc
或者development
下面是我的配置
default_platform(:ios)
platform :ios do
desc "Description of what the lane does"
lane :NonTeacher do #函數(shù)名稱,執(zhí)行打包的時候使用
time = Time.new.strftime("%Y%m%d") #獲取時間格式
version = get_version_number#獲取版本號
ipaName = "Release_#{version}_#{time}.ipa"
gym(
scheme:"NonTeacher", #項目名稱
export_method:"ad-hoc",#打包的類型
configuration:"Release",#模式,默認Release,還有Debug
output_name:"#{ipaName}",#輸出的包名
output_directory:"./build"#輸出的位置
)
end
end
終端先 cd 到項目下,然后執(zhí)行命令fastlane NonTeacher
下面就是打包成功的截圖了
然后我們就可以在項目下看到包了
關(guān)于gym插件的更多用法可以在這里查看https://docs.fastlane.tools/actions/gym/
上傳到蒲公英或者fir
1、上傳蒲公英
1)、cd到項目下, 安裝pgyer
插件 執(zhí)行命令fastlane add_plugin pgyer
2)、重新編寫項目目錄下的Fastfile
文件,如下:
3)、cd 到項目下,執(zhí)行命令fastlane NonTeacher
,打包上傳成功
注意點:
如果遇到這種情況:
Could not find action, lane or variable 'pgyer'. Check out the documentation
可能是你安裝pgyer
插件的時候,不是在項目下安裝的,這個插件必須在項目下面安裝
2、上傳至fir
1)、cd到項目下, 安裝fir
插件,執(zhí)行命令fastlane add_plugin firim
2)、重新編寫項目目錄下的
Fastfile
文件,如下:3)、cd 到項目下,執(zhí)行命令
fastlane NonTeacher
,打包上傳成功上傳到appstore
本人沒有嘗試過,還是習慣用xcode去上傳,感覺放心,如果需要了解,可以看看這篇文章http://www.lxweimin.com/p/c09097211cd4
發(fā)送郵件
先說一下fastlane中的函數(shù)
執(zhí)行順序 | 方法名 | 說明 |
---|---|---|
1 | before_all | 在執(zhí)行 lane 之前只執(zhí)行一次 |
2 | before_each | 每次執(zhí)行 lane 之前都會執(zhí)行一次 |
3 | lane | 自定義的任務 |
4 | after_each | 每次執(zhí)行 lane 之后都會執(zhí)行一次 |
5 | after_all | 在執(zhí)行 lane 成功結(jié)束之后執(zhí)行一次 |
6 | error | 在執(zhí)行上述情況任意環(huán)境報錯都會中止并執(zhí)行一次 |
我們使用的是after_all
,具體配置如下:
坑
1、如果執(zhí)行sudo gem install fastlane -NV
報錯:ERROR: While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/commander
換成這樣的安裝命令:
sudo gem install -n /usr/local/bin fastlane
2、如果執(zhí)行fastlane init
一直停留在bundle update 不動,如圖
兩種解決方法如下:
1)、結(jié)束進程ctrl +c
,刪除項目下的fastlane
文件夾,使用gem cleanup
清理一下,重新cd到項目下執(zhí)行fastlane init
2)、
查看一下你的源 gem sources -l
如果不是 https://gems.ruby-china.com
嘗試換成 https://gems.ruby-china.com 這個源
先移除你原本的源 gem sources --remove + 源名稱
增加新的源 gem sources --add https://gems.ruby-china.com
3、如果報這種錯誤
解決辦法:
解決這個問題也很簡單,找到你的Xcode路徑,在終端輸入
sudo xcode-select --switch 你的Xcode路徑
1、xcode-select --print-path //查看xcode目前所在路徑
2、 sudo xcode-select --switch /Applications/Xcode10.1.app //切換路徑
這篇文章說了一下經(jīng)常用的一些插件,大家可以看看http://www.lxweimin.com/p/5119c115ec90
基本上就是這些,更多的東西,需要我們自己去探索,了解。
希望大家能提出寶貴的意見,可以給我留言,也可以發(fā)郵件到我的郵箱:namezyqyx@163.com
謝謝大家,如果你有更好的想法或文章請告知,不勝感激。