iOS自動化打包-fastlane-自動化


Fastlane 是一套使用Ruby寫的自動化工具集,旨在簡化Android和iOS的部署過程,自動化你的工作流。它可以簡化一些乏味、單調(diào)、重復的工作,像截圖、代碼簽名以及發(fā)布App。方法簡單粗暴,直接教你如何使用:

  • 安裝xcode命令行工具
$ xcode-select --install

如果沒有安裝,會彈出對話框,點擊安裝。如果已經(jīng)安裝提示xcode-select: error: command line tools are already installed, use "Software Update" to install updates

image

  • 安裝Fastlane
$ sudo gem install fastlane -NV 
或
$ brew cask install fastlane

安裝完畢后執(zhí)行fastlane --version,確認下是否安裝完成和當前使用的版本號(fastlane 2.99.1)。


  • 初始化Fastlane

cd到你的項目目錄執(zhí)行$ fastlane init
當出現(xiàn) What would you like to use fastlane for?1. ... 2. ... 3. Automate App Store Distribution 4. ...

選擇3,然后接著輸入你的開發(fā)者賬號和密碼,登錄后會提示你是否需要下載你的App的metadata。輸入y等待就可以。
這個時候可能會出現(xiàn) fastlane init failed ,就問問你 Would you like to fallback to a manual Fastfile? 那么繼續(xù)選擇 y 接著幾次enter就可以了。


  • fastlane文件出現(xiàn)
    初始化成功后會在當前工程目錄生成一個fastlane文件夾,文件目錄為下。

metadata和screenshots分別對應(yīng)App元數(shù)據(jù)和商店應(yīng)用截圖。

Appfile主要存放App的apple_id team_id
app_identifier等信息

Deliverfile中為發(fā)布的配置信息,一般情況用不到。

Fastfile是我們最應(yīng)該關(guān)注的文件,也是我們的工作文件。


  • Fastfile的配置
fastlane_version "2.99.1"
default_platform(:ios)
now = Time.new.strftime("%Y_%m_%d_%H_%M_%S")
scheme = "你的項目的scheme"
api_key = "蒲公英賬號上面的api_key"
user_key = "蒲公英賬號上面的user_key"
platform :ios do
  desc "Description of what the lane does"
  #這個地方的lane:custom_lane你需要特別注意,后面執(zhí)行打包的時候需要用到這個custom_lane
  lane :custom_lane do
    gym(
        scheme: "#{scheme}",
        #輸出的ipa名稱
        output_name:"#{now} #{scheme}",
        # 是否清空以前的編譯信息 true:是
        clean:true,
        # 指定打包方式,Release 或者 Debug
        configuration:"Release",
        # 指定打包所使用的輸出方式,目前支持app-store, package, ad-hoc, enterprise, development
        export_method:"development",#這里我只是想打包到蒲公英上面做一個測試包,所以選擇developement,如果你要發(fā)布到AppStore,你就要選擇app-store
        # 指定輸出文件夾
        output_directory:"./fastlane/build",
        )
    puts "開始上傳蒲公英"
    pgyer(api_key: "#{api_key}", user_key: "#{user_key}")
end
end


  • 配置蒲公英插件

要實現(xiàn)自動打包到蒲公英平臺,需要給fastlane安裝個蒲公英插件,更多配置查看蒲公英文檔$ fastlane add_plugin pgyer如果未添加蒲公英插件,則后面會報錯,說找不到pgyer插件


  • 執(zhí)行打包

$ fastlane custom_lane desc:測試打包
出現(xiàn)

image

就上傳到蒲公英上面成功了。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。