fastlane: Match管理證書 & 自動打包action

Match

Match是fastlane中的一個插件,他的作用是輕松地在整個團隊中同步您的證書和配置文件。在使用之前需要創(chuàng)建一個私有的git倉庫,并且xcode要使用手動管理證書,不能使用自動管理證書

  • 安裝以及初始化
# 安裝
[sudo] gem install match
# 初始化 cd到項目目錄下
fastlane match init
# 根據(jù)提示進行相關(guān)設(shè)置

執(zhí)行成功后會在fastlane目錄下生成Matchfile文件,可以進行相關(guān)配置

git_url("https://用戶名:密碼@github.com/用戶名/倉庫.git")
storage_mode("git")

type("development") # The default type, can be: appstore, adhoc, enterprise or development

app_identifier("bundle id")
username("蘋果開發(fā)者賬戶") # Your Apple Developer Portal username

# For all available options run `fastlane match --help`
# Remove the # in the beginning of the line to enable the other options

# The docs are available on https://docs.fastlane.tools/actions/match
  • 刪除舊的證書以及配置文件
fastlane match nuke development
fastlane match nuke distribution
  • 生成新的證書以及配置文件
    第一次執(zhí)行的時候 ,會讓你輸入一個密碼,用來對證書的加密。后面其他機器獲取證書的時候會使用到這個密碼
在工程目錄下分別執(zhí)行
fastlane match development
fastlane match adhoc
fastlane match appstore

倉庫下會出現(xiàn)相應(yīng)的目錄以及文件


image.png
  • 其他機器來獲取證書以及配置文件
    因為生產(chǎn)的時候進行了加密, 這里則需要密碼進行解密
astlane match development --readonly
fastlane match adhoc --readonly
fastlane match appstore --readonly
image.png

自動打包

  • Appfile 文件中的內(nèi)容
app_identifier("com.xxxx.xxxx") # The bundle identifier of your app
apple_id("xxxxxxx@xxxx.com") # Your Apple email address
itc_team_name "xxxxxx" # Apple ID 中存在多個team 設(shè)置team名稱 不設(shè)置的話 打包過程中需要選擇


# For more information about the Appfile, see:
#     https://docs.fastlane.tools/advanced/#appfile

  • 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

  begin

    buildN = get_build_number() #get_build_number,獲取工程中的build number
    last_build = buildN.to_i 

  end


  lane :match_all do
        sh "fastlane match development --readonly"
        sh "fastlane match adhoc --readonly"
        sh "fastlane match appstore --readonly"
  end


  desc "打包并上傳至app-store"

  lane :app_store do |options|
    name = options[:name]

    now_build = last_build + 1

    #增加build number
    increment_build_number(
      build_number: now_build
    )

    #導(dǎo)出ipa包
    gym(
      clean: true,
      scheme: name,
      export_method: "app-store",
      output_directory: "./fastlane/build",
      output_name: "#{name}_appstore_#{now_build}"
    )

    #上傳至app-store
    deliver(
      force: false,              #是否跳過HTML驗證報告,默認false
      skip_metadata: false,      #是否跳過上傳metadata,默認false
      skip_screenshots: false    #是否跳過上傳屏幕截圖,默認false
    )
  end



  desc "打包并上傳測試版至testflight"
  lane :beta_testflight do |options|
    name = options[:name]
    now_build = last_build + 1
    #增加build
    increment_build_number(build_number: now_build)
    #編譯App
    gym(
      clean: true,
      scheme: name,
      configuration: "Release",
      export_method: "ad-hoc",
      output_directory: "./fastlane/build",
      output_name: "#{name}_testflight_#{now_build}",
      # include_bitcode: false, #bitcode
      export_options: {   #指定配置文件等設(shè)置,如果在Xcode中配置好了可不傳
      provisioningProfiles: { 
        "bundle id" => "match AdHoc 配置文件名稱",
      }
    }
    )
    #上傳至testFlight
    upload_to_testflight(
      skip_waiting_for_build_processing: true  #是否跳過等待apple處理的過程
    )
  end



  lane :adhoc_pgyer do |options|

    name = options[:name]

    gym(
      clean:true, # 是否清空以前的編譯信息 true:是
      scheme: name, # 自己項目名稱
      workspace: "#{name}.xcworkspace", # 自己項目名稱xcworkspace(使用cocoapods才會生成)
      export_method:"ad-hoc", #app-store,ad-hoc,enterprise,development
      configuration:"AdHoc",
      output_directory:"./fastlane/build", # 打包后的 ipa 文件存放的目錄
      export_xcargs: "-allowProvisioningUpdates", #訪問鑰匙串
      output_name: "#{name}.ipa",# ipa 文件名
      silent:true,#隱藏沒有必要的信息
      export_options: {
        provisioningProfiles: {
        "bundle id" => "match AdHoc 配置文件名稱",# bundleid,打包用的證書名字
        }
      }
    )

    pgyer(
      api_key: "xxxxx", # 從蒲公英項目詳情中獲取的 apikey
      user_key: "xxxxx", # 從蒲公英項目詳情中獲取的 userkey
      password: "xxxxx", # 密碼
      update_description: "fastlane 測試"#"description" # 本次測試更新的文字說明(參數(shù)設(shè)置)
    )
  end

end

  • 使用
  1. cd到項目目錄
  2. 打包并上傳至app-store
fastlane app_store name:項目名稱
  1. 打包并上傳至app-store
fastlane app_store name:項目名稱
  1. 打包并上傳測試版至testflight
fastlane beta_testflight name:項目名稱
  1. 打包并上傳至蒲公英
fastlane adhoc_pgyer name:項目名稱

遇到的問題

Before being able to increment and read the version number from your Xcode project, 
you first need to setup your project properly. Please follow the guide at 
https://developer.apple.com/library/content/qa/qa1827/_index.html

解決方法:可以查看提示中的網(wǎng)址 https://developer.apple.com/library/content/qa/qa1827/_index.html 進行設(shè)置

Cannot set build number with plist path containing $(SRCROOT)
Please remove $(SRCROOT) in your Xcode target build settings

解決方法:將inif.plist file 值中的$(SRCROOT)去掉,改為相對路徑

image.png

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容