關于fastlane證書復用問題

最近使用fastlane,每當新建一個project/target的時候,當執行 match development/adhoc/appstore時候,不同的bundle id對應的target,每次都會去重新生成certificate,注意不是Provision Profile,這就很麻煩了,因為蘋果的個人開發者賬號,certificate生成是有數量限制的。 developmentdistribution證書類型貌似都是只能生成2個。所以如果按照fastlane那種做法的話,我們只能給兩個app裝到真機里面玩玩。這就怕不能愉快的玩下去了,所以我們就得考慮如何復用已存在certificate,下面就是介紹如何復用。

合并已有證書到fastlane match

首先一個很重要的概念就是cert id, 拿到已有證書的cert id并告訴fastlane, fastlane知道了就不會去重新生成certificate,只會去生成Progision Porfile

下面一段ruby代碼就是獲取cert id:

require 'spaceship'

Spaceship.login('your@apple.id')
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

執行上述代碼,會輸出相應的證書信息,如果該賬號下有多個certificat,會全部輸出,包括developmentdistribution

保持好你需要的復用的證書cert id

創建一個遠程git倉庫,保存你的certificatesprovisioning profiles

  • iOS/macOS證書的工作主要就是圍繞certificatesprovisioning profiles這兩個文件進行的。
  • 倉庫目錄下創建certs/distributioncerts/development目錄,分別存放生成和開發環境下的相關證書文件

生成符合fastlane match的證書

  • 鑰匙串中導出已有證書的certificate.cercertificate.p12文件

  • run openssl pkcs12 -nocerts -nodes -out key.pem -in certificate.p12.
    It will extract the private key to a key.pem file.

  • encrypt the files with

    openssl aes-256-cbc -k your_password -in key.pem -out cert_id.p12 -a
    openssl aes-256-cbc -k your_password -in certificate.cer -out cert_id.cer -a
    

執行完上述步驟后,就生成了fastlane match想要的certificate,當執行match development/adhoc/appstore命令后,match就不會去Apple Development Center重新生成certificate了,而是拿現有的了,然后分別丟進對應git倉庫目錄中,提交、推送到遠程。


本文參考自:Simplify your life with fastlane match

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

推薦閱讀更多精彩內容