前言
团队开发中, 经常会遇到新成员加入或者证书及配置文件的变更, 此时往往会造成一堆证书 / pp 文件失效问题, 故我们可以使用 fastlane 的 match 进行统一管理配置
我们的目标 ---> 使用一个终端命令配置好一个项目所需要的所有证书及配置文件, 从此妈妈再也不用担心我证书失效了
关于 fastlane 的基本介绍及使用可以看这里: fastlane 的基本使用(自动化打包发布) https://www.jianshu.com/p/90c220e0b54c
在使用 fastlane 管理证书前, 要先注册一个私有的仓库, 若有私有服务器则放在服务器上即可 本编文章以码云 https://gitee.com/?from=osc-index 作为管理仓库
match
match 是 fastlane 的一个功能组件, 能自动从苹果官方上下载证书和 pp 文件同步到我们的 Git 仓库中
安装及初始化
默认项目已经进行 fastlane 初始化, 打开 Matchfile 文件 cd 到当前项目文件下, 并执行
- [sudo] Gem install match
- fastlane match init
执行成功后, 会在 fastlane 文件夹下生成 Matchfile 文件
- 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 文件, 要先在官网上将证书和 pp 文件全部删除, 也可以执行以下命令来删除
- fastlane match nuke development
- fastlane match nuke distribution
生成证书和 pp 文件
在工程目录下分别执行
- fastlane match development
- fastlane match adhoc
- fastlane match appstore
首次执行时, 会要求输入一个密码, 用来对证书进行加密, 后续其他机器获取证书时使用该密码进行解密, 输入密码后继续按照终端提示进行下一步操作, 注意, 此时会自动在 Apple Developer 中生成新的证书及配置文件来进行使用
完成后, Git 仓库就会生成对应的 certs 及 profiles 文件夹来存放证书和配置文件
团队管理
当有新成员加入时, 执行
- fastlane match development --readonly
- fastlane match adhoc --readonly
- fastlane match appstore --readonly
并输入对应的加密密码来获取 xcode 要取消 Automatically manage signing, 并将获取到的 pp 文件放到对应的 Signing 配置中, 至此就配置完成啦!
手动上传证书和 profile 文件(不推荐)
实际开发过程中, 项目的证书及配置文件都是已经建立好的, 可能会由于种种原因无法进行删除重新配置, 下面介绍如何使用已有的证书和配置文件来进行团队证书管理
创建 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
生成加密后的 p12
执行
openssl 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 打包上传使用口感更加哦~
来源: https://juejin.im/post/5bd81e5ce51d450c445ae774