介紹
其實自動化打包工具有很多,用的比較多的有 Jenkins 恶耽、Python密任、fastlane。曾經(jīng)一直使用的 Jenkins 來構建驳棱,但是 Jenkins 需要我們配置的東西比較多(倉庫地址批什、git/svn 賬號和密碼、分支等)而 fastlane 是我目前遇到最簡單快速的(iOS社搅、Android都支持)github地址驻债、文檔地址
安裝前準備工作
- 首先確認是否安裝了 ruby ( 默認 mac 都已經(jīng)安裝好了)
ruby -v
檢測 ruby 版本.png
- 查鏡像、修改鏡像
查看源:gem sources
刪除源:gem sources --remove https://gems.ruby-china.org/
更換源:gem sources -a https://gems.ruby-china.com
開始安裝
- 安裝 fastlane
執(zhí)行命令:sudo gem install fastlane -NV
如果出現(xiàn) 錯誤ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /usr/bin directory.
表示沒有權限形葬,需要把安裝路徑也加進去合呐。
重新執(zhí)行:sudo gem install fastlane -NV -n /usr/local/bin
等待安裝成功如下圖
安裝成功.png
使用
- 打開終端 cd 到你的項目下
- 執(zhí)行 fastlane 命令
fastlane init
如圖:
執(zhí)行命令.png
下面會有四個選項供你選擇
- 自動截屏。幫我們自動截取APP中的截圖.
- 自動發(fā)布beta版本用于TestFlight.
- 自動發(fā)布到AppStore.
- 手動設置.
這里我們選擇 4 笙以、一直按 enter 就ok了
配置
上一步執(zhí)行成功 我們項目會多出這兩個文件
FB95F6D8-FA51-44E1-8AD0-2C0696828770.png
- 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 就是我們工程的 boundle_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í)行的插件拆祈、命令等操作用于打包。
下面是我項目的配置
# 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 :Demo do #函數(shù)名稱倘感,執(zhí)行打包的時候使用 (冒號后面不能有空格)
# add actions here: https://docs.fastlane.tools/actions
time = Time.new.strftime("%Y%m%d") #獲取時間格式
version = get_version_number#獲取版本號
ipaName = "Debug_#{time}.ipa"
gym(
scheme:"Demo", #項目名稱
export_method:"development",#打包的類型
configuration:"Debug",#模式放坏,默認Release,還有Debug
output_name:"#{ipaName}",#輸出的包名
output_directory:"./build/#{version}"#輸出的位置
)
end
end
重新 cd 到項目目錄老玛,執(zhí)行命令 fastlane Demo. 成功截圖如下:
image.png
上傳蒲公英
- cd到項目下淤年、安裝 pgyer 插件
- 執(zhí)行命令
fastlane add_plugin pgyer
- 重新修改 Fastlane 文件,如下:
# 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 :Demo do #函數(shù)名稱蜡豹,執(zhí)行打包的時候使用 (冒號后面不能有空格)
# add actions here: https://docs.fastlane.tools/actions
time = Time.new.strftime("%Y%m%d") #獲取時間格式
version = get_version_number#獲取版本號
ipaName = "Debug_#{time}.ipa"
gym(
scheme:"Demo", #項目名稱
export_method:"development",#打包的類型
configuration:"Debug",#模式麸粮,默認Release,還有Debug
output_name:"#{ipaName}",#輸出的包名
output_directory:"./build/#{version}"#輸出的位置
)
pgyer(api_key: "#{api_key}", user_key: "#{user_key}")
end
end
重新執(zhí)行 fastlane Demo
上傳成功.png
參考文章:
gym 插件更多用法
cocoachina文章