This article will focus on how ios can be delivered to required platforms via Fastlane packaging. Android packaging will be in Part 2. Jenkins integration will be in Part 3
preface
In APP before development, the company’s technical director has been asking me the APP automated packaging deploy the engineering task, continuous integration for this technology is very interested in seeing what I’m sure, given the APP business development mission, and the cause of the relatively low priority, wait less busy to have time to study, I have read some relevant documents recently, and the summary is as follows:
-
Continuous integration:
Jenkins is mostly used, and our back-end services are also integrated with Jenkins, so CI platform is not needed to be considered.
-
Ios packaging:
Most of the articles are based on Jenkins installation of Xcode related plug-ins to build the Xcode packaging environment and configure related plug-ins of certificates, certification files and key chains. The overall process is cumbersome, and any error in process sequence and configuration will lead to packaging failure. In addition, I heard that the update frequency of Jenkins’ Xcode plug-in is very slow, which may not meet the use of the latest version of Xcode. After referring to the configuration of some articles, I packaged the test version of IPA and pushed it to Dandelion, but the construction of publishing it to Appstore failed.
After two or three days, I was tired of eating until I discovered Fastlane!
The body of the
I will not list the introduction of Fastlane here, there are too many articles on the Internet to introduce it, you can refer to the Chinese document for a quick understanding.
After reading the document, I felt like I opened the door to a new world, and just a few features were attractive enough.
Such as:
- Automatically package beta releases of ipA to Testflight;
- Automatically in the ITC (appstoreconnect.apple.com/) to create applications, as well as a variety of yuan…
- Automatically publish to the appstore;
- Automatically generate app screenshots of the store;
- Automatically create certificates and authentication files;
As an app developer, I believe everyone has had a love and hate relationship with xcode certificates and certification files.
Here’s a diagram to summarize fastlane’s process and functionality:
Fastlane manages a collection of tools, all of which are developed in Ruby. Each tool is responsible for only one task, and you can flexibly build the use and flow of these tools through Fastlane’s configuration files
Package => Automated tests => Publish test packages => Publish official packagesCopy the code
One-stop service!
I just want to know what’s wrong with you?
Start to toss…..
After two days of torturing, successfully completed
- Ipa files pushed to TestFlight, dandelion, firm;
- Automatically upload metadata to ITC;
- Automatically upload IPA to ITC and submit it to Appstore for review;
So, if you are reading this article and want to fulfill the above requirements, you can refer to the following content I shared.
Fastlane installation
1. Install the Xcode command-line tool
xcode-select --install
Copy the code
If the following information is displayed, the Xcode cli tool has been installed. Otherwise, a dialog box is displayed. Select Install.
$ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
Copy the code
Installation interface:
2. Use RubyGems to install Fastlane
RubyGems is recommended, fastlane is a tool written in Ruby, so this is a friendly way to install, not error prone.
If you are a Mac user, the Mac comes with ruby, but this is not enough, you need 2.0 or later, check your version:
ruby -v
Copy the code
My current version:
$ruby -v Ruby 2.6.3 P62 (2019-04-16) [x86_64-darwin19]Copy the code
Ruby management recommends using RVM, a tool similar to Node’s NVM that provides a convenient way to manage and switch between multiple versions of Ruby environments.
Check that you are currently using system Ruby
which ruby
Copy the code
If the result is:
/usr/bin/ruby
Copy the code
Note The Mac operating system is built with Ruby. Therefore, install RVM first, which requires GPG and mpapis
(Trouble?)
Have no matter, pit all run over, follow to go to….
3. Ruby environment construction
- Install GPG through Homebrew
brew install gnupg
Copy the code
- After installing GPG, install the mpapis public key
IO/RVM /install to view the latest public key
Bring it over and install it
gpg --keyserver hkp://pgp.mit.edu --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
Copy the code
- RVM for installing the latest version of Ruby
\curl -sSL https://get.rvm.io | bash -s stable --ruby
Copy the code
- RVM lists the Ruby versions available for RVM
$RVM list =* ruby-2.6.3 [x86_64]# => - current
# =* - current && default
# * - default
Copy the code
- Again using
which ruby
View the current Ruby version
Return/Users/XXX /. RVM/rubieslast/ruby – 2.6.3 / bin/ruby
RVM installed Ruby is now used, and the Ruby environment is now over!
Install via RubyGems:
sudo gem install fastlane -NV
Copy the code
You can also install it via Homebrew (you won’t choose this option after all this effort) :
brew cask install fastlane
Copy the code
4. The initialization
Fastlane Init is executed in the project directory
The following options appear when you install
📸 Automate screenshots 2. 👩✈️ Automate beta distribution to TestFlight 3. 🚀 Automate 🛠 Manual setup - Manually setup your project to automate your (manually configure)Copy the code
New users will definitely struggle with this, depending on the situation, the automatic screen capture function is definitely not the first to need, release to the appstore is not the first to be done, manual configuration of the first you can configure?
So this option 2, and then enter all the way, will let you enter apple developer ID, is your email and password, login from the command line apple developers to download your certificate such as configuration, log on to the ITC and existing information from ITC pull project, if open the apple two-factor authentication, enter the code will be prompted to login
Two-factor Authentication (6 digits code) is enabled for account '[email protected]'
Copy the code
To avoid entering a verification code each time you log in, the official solution is provided.
There are also related issues in the command to look up the solution, the interface and prompts are very introductory and friendly, this is the most thoughtful command line tool I have ever used!
After the command is executed, the Fastlane folder, Gemfile file, Appfile, and Fastfile files are generated.
Appfile: Stores information about developer accounts
Fastfile: Core file for command line calls and specific processes, lane relative to an action method or function
Gemfile is similar to the Podfile of Cocopods
Env configuration environment variables (not automatically generated after fastlane init initialization, you can create your own if necessary
Open the project and look at the file you just generated. You may notice that there is no code highlighting…. Since Fastlane is written in Ruby, it is necessary to support Ruby. Here I use VS Code to search for Ruby plug-in installation.
(Webstorm didn’t find ruby plugins)
5. Install required plug-ins
Fastlane plug-ins are packages of one or a group of actions that are published separately from Fastlane.
You can search for plug-ins from the command line
# View all plug-ins
fastlane search_plugins
Copy the code
# Install method
fastlane add_plugin [name]
# Common plugins
fastlane add_plugin versioning
fastlane add_plugin firim
fastlane add_plugin pgyer
Copy the code
The Pluginfile file is generated when the plug-in is first installed
# Autogenerated by fastlane
#
# Ensure this file is checked in to source control!
gem 'fastlane-plugin-firim'
gem 'fastlane-plugin-pgyer'
gem 'fastlane-plugin-versioning'
Copy the code
The Gemfile file will be automatically added
plugins_path = File.join(File.dirname(__FILE__), 'fastlane'.'Pluginfile')
eval_gemfile(plugins_path) ifFile.exist? (plugins_path)Copy the code
Plug-in description:
-
fastlane-plugin-versioning
The actionIncrement_build_number embedded in Fastlane uses the Agvtool provided by Apple to change the build and version numbers of all targets. If you have multiple targets in a project, all builds are incremented by 1 each time you Build. With Fastlane-plugin-versioning, you can not only specify the target Build, but also specify the Version directly, and specify the Version number (major/ Miner /patch). This is very important. And this plug-in can also be very convenient to change the Version number of Android, plug-in top.
-
fastlane-plugin-pgyer
Upload to the Dandelion distribution platform.
-
fastlane-plugin-firim
Upload to FIrim.
6. Configure environment variables
Create a. Env file, where you can configure all custom variables such as accounts, keys, paths, etc. After defining, the three Fastlane configuration files (Appfile, Deliverfile, Fastfile) can read configuration information from the. Env file.
Official Documentation Reference
If you don’t see any syntax highlighting in env files, or if obsessionis uncomfortable, you can install the dotEnv plugin in VS Code.
Github.com/bkeepers/do…
Env file configuration for reference:
App_Identifier = "com.xx.xxx" # Apple email address Apple_Id = "[email protected]" # TeamId Team_Id = "xxx" # target scheme Scheme =" XXX "# xcodeproj xcodeproj ="xxx.xcodeproj" # xcworkspace ="xxx.xcworkspace" # ipa Appstore_Output_Path = "builds/appstore" # IPA output path -- TestFlight TF_Output_Path = "./builds/testflight" # api_key Pgy_Api_Key = "XXX" # user_key Pgy_User_Key = "XXX"Copy the code
ENV[‘Apple_Id’]
apple_id("[email protected]") ===> apple_id ENV['Apple_Id']
Copy the code
Fastfile configuration:
default_platform(:ios)
platform :ios do
# before all lanes are executed
# Use the environment variable to supply this password to Fastlane to solve the special password generated by two-factor authentication
before_all do
ENV["FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD"] = "xxx"
end
desc "Release test version to TestFlight"
lane :beta_tf do
increment_build_number_in_plist(target: [target_name])
increment_version_number_in_plist(
target: [target_name],
)
get_certificates( # Create or get certificate, and install it
output_path: "./builds" # Download certificate in the build folder (you don't need to create the folder)
)
get_provisioning_profile( # Create or get provisioning profile
output_path: "./builds".# Download provisioning profile in the build folder
filename: "provisioning.mobileprovision" # Rename the local provisioning profile
)
update_project_provisioning( # Set the project provisioning profile (related in Xcode to the General > Signing Release section)
xcodeproj: ENV['Xcodeproj'],
target_filter: ENV['Scheme'].# Name of your project
profile: "./builds/provisioning.mobileprovision",
build_configuration: "Release"
)
update_project_team( # Set the right team on your project
teamid: CredentialsManager::AppfileConfig.try_fetch_value(:team_id)
)
gym(
workspace: ENV['Workspace'],
scheme: ENV['Scheme'],
clean: true,
export_method: "ad-hoc".# Valid values are: app-store, ad-hoc, package, enterprise, development
export_options: {
provisioningProfiles: {
"com.xxx.xxx"= >"xxx",
}
},
build_path: "./builds/testflight",
output_directory: "./builds/testflight",
output_name: logDirectory
)
upload_to_testflight
end
# Post to Dandelion
lane :beta_pgy do
desc "Release the beta version to dandelion"
# Here is the Debug version of typing
gym(
scheme: ENV['Scheme'],
clean:true.Clean projects before packing
export_method: "development".Defaults to 'Release'
configuration: "Debug".# environment
output_directory: ENV['Pgy_Output_Path'],
output_name: logDirectory,
export_options: {
provisioningProfiles: {
"com.xxx.xxx"= >"xxx",}})# Upload version to dandelion platform
pgyer(
api_key: ENV["Pgy_Api_Key"],
user_key: ENV["Pgy_User_Key"],
update_description: "update by fastlane"
)
Send notifications in the macOS notification bar
notification(subtitle: "Upload completed", message: "The latest test package has been uploaded to the Dandelion platform.")
end
lane :release do
desc "Release the official version to the appstore"
# Download certificate
get_certificates(
output_path: "./builds"
);
Download the authentication file
get_provisioning_profile(
output_path: "./builds"
);
#get_push_certificate # Get the official push certificate
# pull the latest code
git_pull
# add version number
# using document at https://github.com/SiarheiFedartsou/fastlane-plugin-versioning
Version_number: '2.1.1' # Set a specific version number
# eg: bump_type: 'minor' # Automatically increment minor version number
increment_version_number_in_plist(
bump_type: 'patch'.# Automatically increment patch version number(patch/minor/major)
target: ENV['Scheme']);Get version from the latest release branch name.
# `pattern` is pattern by which version number will be found, `#` is place where action must find version number.
# Default value is 'release-#'(for instance for branch name 'releases/release-1.5.0' will extract '1.5.0')
# version = get_version_number_from_git_branch(pattern: 'release-#')
# increase build number
latest_build_number = lane_context[SharedValues::LATEST_BUILD_NUMBER];
# Automatically increments the last part of the build number.
increment_build_number_in_plist(
target: ENV['Scheme']);# see code signing guide for more information
#sync_code_signing(type: "appstore");
# packaged
gym(
scheme: ENV['Scheme'],
configuration: "Release",
clean: true,
export_method:"app-store",
export_options: {
provisioningProfiles: {
"com.xxx.lph"= >"xxx",}});# Upload to ITC
deliver
Send notifications in the macOS notification bar
notification(subtitle: "Upload completed", message: "The latest official package has been uploaded to the Appstore.")
end
end
Copy the code
7. Configuration metadata
Run the following command to initialize metadata. After a few minutes, all ITC metadata and snapshots are downloaded to the local computer
fastlane deliver init
Copy the code
The metadata folder contains a large number of files, but the configuration of a single attribute is stored in a separate. TXT file. The Deliverfile can be configured with a higher priority than the configuration in the. So we’re going to create Deliverfile.
Here is my configuration:
# The Deliverfile allows you to store various App Store Connect metadata
# For more information, check out the docs
# https://docs.fastlane.tools/actions/deliver/
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # basic information # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# 1 bundle identifier
app_identifier "xxx"
# 2 User name,Apple ID email address
username "[email protected]"
# 3 Copyright Notice
copyright "xxx"
# 4 Supported languages
supportedLanguages = {
"cmn-Hans"= >"zh-Hans"
}
# 5 App name
name(
'zh-Hans'= >"xxx"
)
# 6 Subtitle
subtitle(
'zh-Hans'= >"xxx"
)
# Application description
description({
'zh-Hans'= >" xxx "
})
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # category configuration # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
See https://github.com/fastlane/fastlane/blob/master/deliver/Reference.md # category list Settings
# Set the App category. You can set a primary category and a secondary category.
# Main categories
primary_category "xxx"
# Primary category First subcategory
primary_first_sub_category
The second subcategory
primary_second_sub_category
# Secondary category to set None
secondary_category
# Set the minor first subcategory none
secondary_first_sub_category
# Set secondary second subcategory none
secondary_second_sub_category
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # keyword \ to describe the information such as # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# key
keywords(
'zh-Hans'= >"xxx,xxx,xxx"
)
# Marketing address
marketing_url({
'zh-Hans'= >"http://xxx.cn"
})
# Private address
privacy_url({
'zh-Hans'= >"http://xxx.cn"
})
# Support url
support_url({
'zh-Hans'= >"http://xxx.cn"
})
Release notes, version updates
release_notes({
'zh-Hans'= >"Fixed some bugs, improved user experience, recommended updates!"
})
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # submit information such as # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# 1 Submit audit information: encryption, IDFA, etc
submission_information({
export_compliance_encryption_updated: false,
export_compliance_uses_encryption: false,
content_rights_contains_third_party_content: false,
add_id_info_uses_idfa: false
})
# 2 Contact information of the app Review team
app_review_information(
first_name: "x",
last_name: "x",
phone_number: "+86xxx",
email_address: "[email protected]",
demo_user: "xxx",
demo_password: "xxx",
notes: ""
)
Export compliance documents
trade_representative_contact_information(
first_name: "",
last_name: "",
address_line1: "xxx",
address_line2: "",
address_line3: "",
city_name: "Beijing",
state: "",
country: "China",
postal_code: "xxx",
phone_number: "",
email_address: "",
trad_name: "xxx",
is_displayed_on_app_store: false
)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # other information # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# 1 App price
price_tier 0
# 2 Automatically publish app: false, you need to publish app manually
automatic_release false
# 3 Icon path
app_icon './fastlane/metadata/app_icon.jpg'
# Skip HTML report file validation
force true
Submit after upload for review
submit_for_review false
Copy the code
After configuring Deliverfile, you can delete the text configuration in the Metadata folder.