preface
In team development, new members or changes in certificates and configuration files will often cause a lot of certificate/PP files invalid. Therefore, we can use Match of Fastlane for unified management and configuration
Our goal is to use a terminal command to configure all the certificates and configuration files needed for a project, so that my mother no longer has to worry about my certificate failure
A basic introduction to and use of Fastlane can be found here: Basic Use of Fastlane (Automated packaging distribution)
Before using the Fastlane management certificate, you need to register a private repository. If there is a private server, you can put it on the server and use the code cloud as the management repository
match
Match is a fastlane feature that automatically downloads certificates and PP files from Apple and synchronizes them to our Git repository
Installation and initialization
The default project is already fastlane initialized, open the Matchfile file CD to the current project file, and execute
[sudo] gem install match
fastlane match init
Copy the code
After successful execution, the Matchfile file is generated in the Fastlane folder
git_url("https://gitee.com/xxxx/xxxxxxx.git") // Create a new project on the code cloud and copy the address heretype("development") # default match to synchronize type
app_identifier("bundle Id") #bundleId = ["bundleId1","bundleId2"]
username("[email protected]") # Apple Developer account
# For all available options run `fastlane match --help`
# Remove the # in the beginning of the line to enable the other options
Copy the code
Delete the old certificate and PP file
If the current project already has certificates and PP files, delete them from the official website or run the following command to delete them
fastlane match nuke development
fastlane match nuke distribution
Copy the code
Generate certificates and PP files
Run fastlane match development fastlane match adhoc fastlane match appstore in the project directoryCopy the code
Team management
Execute when a new member is added
fastlane match development --readonly
fastlane match adhoc --readonly
fastlane match appstore --readonly
Copy the code
To enable Automatically manage Signing, add the pp file to the signing configuration. This configuration is complete.
Manually uploading certificates and profile files (not recommended)
In the actual development process, the certificate and configuration file of the project have been established, and may not be deleted and reconfigured for various reasons. The following describes how to use the existing certificate and configuration file to manage the team certificate
Create a ruby.rb file and copy in the following code to replace the comments
require 'spaceship'
Spaceship.login('[email protected]') # Enter the corresponding Apple account
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
Copy the code
The terminal executes Ruby ruby.rb to find existing certificates and record the Cert ID to be used later
Create the certs and Profiles folders in the Git repository, as shown below, and distinguish the corresponding types
Then download the existing certificate and mobileprovision file from Apple Developer, import the certificate into the key, and generate a P12 file
- perform
Openssl pkcs12 -nocerts -nodes -out key.pem -in {certificate}.p12
Pem file generated - perform
Openssl AES-256-cbc -k {password} -in key.pem -out {cert_id}.p12 -a
Generate an encrypted P12 - perform
Openssl AES-256-cbc -k {password} -in {certificate}.cer -out {cert_id}.cer -a
Generate an encrypted certificate where cert_id is the certificate ID found in the ruby file previously executed
Add the encrypted certificate and P12 to the certs directory in the Git repository. Then, run the Fastlane match command Development/adhoc/appstore will obtain from a git repository of the existing certificate and configuration, so that to reach the entire development team to keep the same certificate and configuration
Mobileprovision also borrows from Apple Developer after download, in the same way of encryption (named {Development/ADHoc/AppStore/InHouse} _bundleId. Mobileprovision) profiles corresponding to the directory that is put in the git repository such as openssl aes-256-cbc -k vanke -in xxxx.mobileprovision -out Development_yyyy -a
The last
After uploading all the certificates and configuration files, you can create a lane in the Fastfile file to load all the certificates and configuration files
platform :ios do.# certificate replaces the bundle ID
lane :match_all do
sh "fastlane match development --readonly"
sh "fastlane match adhoc --readonly"
sh "fastlane match appstore --readonly"
end
...
Copy the code
When a new member joins the project, execute fastlane match_all to synchronize the certificate and upload it with Fastlane package
Q&A
-
Another member displays a message indicating that the account password is incorrect or the git request takes a long time You can change the Matchfile file. The address at git_url should bring the account and password, for example, [email protected] and password 111111. The address should be git_url(“https://[email protected]:[email protected]/user/pr Oject. git”), pay attention to special symbols and Chinese to do URL encode
-
If the team does not share the same developer account for development, but adds developers, the development certificate will become a new corresponding developer certificate each time it is synchronized. It is recommended that the development certificate is not synchronized, and local management is good
Reference: Simplify your life with Fastlane match A new approach to code signing
From: SimonYe