團隊開發中,常常會遇到新成員加入或者證書及配置文件的變動,此時每每會形成一堆證書/pp文件失效問題,故咱們可使用fastlane的match進行統一管理配置node
咱們的目標 ---> 使用一個終端命令配置好一個項目所須要的全部證書及配置文件,今後媽媽不再用擔憂我證書失效了ios
關於fastlane的基本介紹及使用能夠看這裏:fastlane的基本使用(自動化打包發佈)git
在使用fastlane管理證書前,要先註冊一個私有的倉庫,如有私有服務器則放在服務器上便可 本編文章以碼雲做爲管理倉庫macos
match是fastlane的一個功能組件, 能自動從蘋果官方上下載證書和pp文件同步到咱們的git倉庫中xcode
默認項目已經進行fastlane初始化,打開Matchfile文件 cd到當前項目文件下,並執行ruby
[sudo] gem install match
fastlane match init
複製代碼
執行成功後,會在fastlane文件夾下生成Matchfile文件bash
git_url("https://gitee.com/xxxx/xxxxxxx.git") //在碼雲上新建一個項目,將地址複製到這裏
type("development") # 默認match所同步的類型,可無論
app_identifier("bundle Id") #bundleId,若同工程下有多個,則用["bundleId1","bundleId2"]
username("user@fastlane.tools") #蘋果開發者帳號
# For all available options run `fastlane match --help`
# Remove the # in the beginning of the line to enable the other options
複製代碼
若是當前項目已經存在證書和pp文件,要先在官網上將證書和pp文件所有刪除,也能夠執行如下命令來刪除服務器
fastlane match nuke development
fastlane match nuke distribution
複製代碼
在工程目錄下分別執行
fastlane match development
fastlane match adhoc
fastlane match appstore
複製代碼
當有新成員加入時,執行app
fastlane match development --readonly
fastlane match adhoc --readonly
fastlane match appstore --readonly
複製代碼
並輸入對應的加密密碼來獲取 xcode要取消Automatically manage signing
,並將獲取到的pp文件放到對應的Signing配置中,至此就配置完成啦!ide
實際開發過程當中,項目的證書及配置文件都是已經創建好的,可能會因爲種種緣由沒法進行刪除從新配置,下面介紹如何使用已有的證書和配置文件來進行團隊證書管理
建立ruby.rb文件,將如下代碼複製進去,替換掉註釋部分
require 'spaceship'
Spaceship.login('xxxxxx@xxx.com') #輸入對應的蘋果帳號
Spaceship.select_team
Spaceship.certificate.all.each do |cert|
cert_type = Spaceship::Portal::Certificate::CERTIFICATE_TYPE_IDS[cert.type_display_id].to_s.split("::")[-1]
puts "Cert id: #{cert.id}, name: #{cert.name}, expires: #{cert.expires.strftime("%Y-%m-%d")}, type: #{cert_type}"
end
複製代碼
終端執行ruby ruby.rb
查找出如今已有的證書,並記錄下等下要用到的Cert id
在git倉庫建立certs及profiles文件夾,以下圖所示,區分好對應的類型
接着從Apple Developer中下載現有的證書及mobileprovision文件,將證書導入到鑰匙中,並生成p12文件
openssl pkcs12 -nocerts -nodes -out key.pem -in {證書}.p12
生成.pem文件openssl aes-256-cbc -k {密碼} -in key.pem -out {cert_id}.p12 -a
生成加密後的p12openssl aes-256-cbc -k {密碼} -in {證書}.cer -out {cert_id}.cer -a
生成加密的證書 其中cert_id爲前面執行ruby文件所找到的證書id將加密後的證書及P12放入git倉庫的certs目錄對應的類型下,此時再執行fastlane match development/adhoc/appstore
即會從git倉庫中獲取現有的證書和配置,這樣就達到了整個開發團隊保持一樣的證書和配置
mobileprovision同理從Apple Developer上下載後,用一樣方式加密(取名爲{Development/ADHoc/AppStore/InHouse}_bundleId.mobileprovision)放入git倉庫的profiles對應目錄下,例如
openssl aes-256-cbc -k vanke -in xxxx.mobileprovision -out Development_yyyy -a
上傳完全部的證書及配置文件後,可在Fastfile文件中建立一個lane專門用來加載全部的證書和配置文件
platform :ios do
...
#證書 替換bundle id
lane :match_all do
sh "fastlane match development --readonly"
sh "fastlane match adhoc --readonly"
sh "fastlane match appstore --readonly"
end
...
複製代碼
當項目有新成員加入時,執行fastlane match_all
便可同步證書,搭配fastlane打包上傳使用口感更加哦~
其餘成員git時提示帳號密碼錯誤或者git請求時間過長 可更改Matchfile文件,git_url處的地址帶上帳號和密碼,例如帳號123456@qq.com,密碼111111,則地址爲git_url("https://123456@qq.com:111111@gitee.com/user/project.git")
,注意特殊符號和中文要進行url encode
若是團隊不是公用同一個開發者帳號進行開發,而是經過添加開發者的方式,development證書會在每次同步是變成新的開發者對應證書,建議development證書不用同步,本地管理就好
參考: Simplify your life with fastlane match A new approach to code signing