今是昨非

今是昨非

日出江花红胜火,春来江水绿如蓝

iOS 自動打包

iOS 自動打包#

使用 FastLane 打包#

安裝 fastlane#

  • 通過 HomeBrew 安裝
    brew install fastlane

  • 通過 Bundler 安裝

    1. 安裝 bundler
    2. 然後在專案根目錄下創建./Gemfile 文件,編輯內容

// 安裝 bundler
$ gem install bundler


//然後在專案根目錄下創建./Gemfile文件,編輯內容
source "https://rubygems.org"
gem "fastlane"

編輯 Gemfile 文件:


source "https://rubygems.org"
gem "fastlane", "2.180.1"
# 如果使用Cocoapods,需要添加下面這行
gem "cocoapods"

  • 通過 ruby gems 安裝
sudo gem install fastlane

fastlane 安裝成功後,安裝兩個插件,用於版本號管理和打包成功後上傳到對應的第三方平台

// 添加fastlane插件
// versioning使用參考,https://github.com/SiarheiFedartsou/fastlane-plugin-versioning,用於版本號獲取和修改
// firim是fir平台插件

fastlane add_plugin versioning
fastlane add_plugin fir_cli # https://github.com/FIRHQ/fastlane-plugin-fir_cli


// pgyer是蒲公英平台
// fastlane add_plugin pgyer

fastlane 內容編輯#

fir 平台的 firim 相關參數參考:傳送門,最少需要 firim_api_token 參數,可以從自己註冊的 firim 中獲取到,也可以配置如下參數

  • firim_api_token
  • app_name
  • app_desc
  • app_passwd
  • app_version
  • app_build_version
  • app_changelog
  • 等等

編輯 Fastfile,定義一個 Action,名字為 TestFir,指定輸出包名為 (版本號 + 時間),打包後包到目錄為./build 目錄下,打包完成後上傳到 fir。如下


default_platform(:ios)

platform :ios do
  desc "Description of what the lane does"

  lane :TestFir do
    time = Time.new.strftime("%Y%m%d%H%M") # 獲取時間格式,格式參考https://www.runoob.com/python/att-time-strftime.html
    # verion = get_version_number_from_list() # 獲取版本號

    version = get_version_number_from_xcodeproj(build_configuration_name: 'Release') # 使用參考GitHub鏈接,https://github.com/SiarheiFedartsou/fastlane-plugin-versioning

    ipaName = "Release_#{version}_#time.ipa" # 生成ipa包的名字格式

    gym(
      clean: true, # 打包前清理專案
      silent: true, # 隱藏沒有必要的信息
      scheme: "Your Scheme Name", # 指定專案的scheme名稱
      export_method: "ad-hoc", # 打包的類型,有:ad-hoc, enterprise, app-store, development
      configuration: "Release", # scheme: 默認為Release,還有Debug
      output_name: "#{ipaName}", # 輸出的報名
      output_directory: "./build" # 輸出的位置
    )
    # 自己的fir賬號,可配置內容參考https://github.com/FIRHQ/fastlane-plugin-fir_cli
    fir_cli api_token: "xxx",  changelog: "My First Fir Upload"
    # 蒲公英的配置 替換為自己的api_key和user_key
    # pgyer(api_key: "******", user_key: "******",update_description: options[:update_info])
  end

end

使用時,在命令行輸入 fastlane TestFir 即可

fastlane TestFir

如果想要在執行命令時從外部傳入參數,則可以按照下面的方式使用,在 do 後面添加 |options|,使用時,options [] 這種方式來獲取從外面傳入的值

lane :ActionName do |options|
    gym(
      configuration: options[:configuration],#環境
      )
    
    # 自己的fir賬號
    fir_cli api_token: "xxx",  changelog: options[:changelog]
  end

從外面調用的方式如下:

fastlane ActionName configuration:"adhoc" changelog:"first submit"

使用 Jenkins 打包,未完待續#

參考#

iOS 之 自動打包 fastlane + fir + pgy 【進階使用】

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。