First, environmental detection

Click here to go to the official website

Because Fastlane is written in Ruby, you need to check the current Ruby version. To ensure that the Ruby version is 2.0 or higher, enter the following command on the terminal:

$: ruby -v (# or  `ruby --version`)
Copy the code

If Ruby is less than 2.0. The following steps are required:

$: RVM remove versionNumber (#versionNumber is the current Version of Ruby on the Mac.)Copy the code
$RVM list known (# list available Ruby versions)Copy the code
$: RVM install versionNumber (#versionNumber is the required Ruby version)Copy the code

Fastlane configuration

  1. Xcode needs to be installed, command line installation needs to execute terminal type:
xcode-select --install
Copy the code
  1. There are two ways to continue installing Fastlane, the first is through RubyGems:
sudo gem install fastlane -NV
Copy the code

The second via HomeBrew:

brew cask install fastlane
Copy the code
  1. Press CMD + Shift +. (CMD + shift +.) to set up the Environment variables. Three buttons to display hidden files at user level, find.bash_profile to edit.

<1> This file can be opened by dragging it to the Xcode icon on the shortcut bar, or it can be edited by using the terminal vi. Bash_profile. Fastlane requires some environment variables set up to run correctly. In particular, having your locale not set to a UTF-8 locale will cause issues with building and uploading your build. In your shell Profile add the following lines) :

export LC_ALL=en_US.UTF-8

export LANG=en_US.UTF-8
Copy the code

You can find your shell profile at ~/.bashrc, ~/.bash_profile, ~/.profile or ~/.zshrc depending on your system.

< 2 > : The bash_profile file is not available on the new computer. In this case, you need to manually create the bash_profile file, CD the terminal to the macUser (user name) file (either directly open or command+T to open another terminal interface). Step by step, enter the following command:

$: touch.bash_profile $:vi. Bash_profile (# also use open.bash_profile)Copy the code

After opening bash_profile, add the commands in <1>.

4, use Gemfile

Gemfile is generated by manual terminal input, but fastlane init indicates that Gemfile is directly generated by fastlane init.

source "[https://rubygems.org](https://rubygems.org/)"

gem "fastlane"
Copy the code

Baidu bing search said that the source should be changed to ruby.taobao.org/, which is the mirror image of Taobao. Here there may be another pit caused by agent reasons, or there may be other pits that are not recognized. What will you say later? If it weren’t for agility tests, skull pain and hair roots)

Iii. Ipa package is automatically used in the project

1. With Fastlane configured, you can start using the project directory.

CD To the corresponding project, continue terminal input:

fastlane init
Copy the code

You’ll see fastlane files and Gemfile files generated that contain at least FastFile and Appfile. There are four options. 1-2-3 involves the login account and password operation. I am authorized by P12, because as a team member, I do not need a password. The P12 file contains the description file required for storing enterprise packages.

Appfile: Stores some common information, such as app_identifier, apple_id, team_id, ITC_team_id, etc.

Fastfile: Used to define all Lane tasks.

Gemfile: not currently configured, the search feels like a tool for managing Fastlane after many errors and issues.

2. Perform task definition coding for Fastlane.

The default OS is iOS. You can run commands to change the OS.

The default generated Fastlane template is:

default_platform(:ios)

platform :ios do

  desc "Description of what the lane does"

  lane :custom_lane do

    # add actions here: [https://docs.fastlane.tools/actions](https://docs.fastlane.tools/actions)

  end

end
Copy the code

Custom_lane is the function name, fastlane custom_lane to perform the lane in the current minimum domain do{… } behavior in end.

<1>: Define lane.

>>>get_certificates # obtain the certificate >>>get_provisioning_profile # obtain the description file >>> Sigh (adhoc:false) >>>build_app(workspace: // Use cocoapod >>>upload_to_app_store(skip_metadata: true, skip_screenshots: True) // Upload to appStore >>> Changelog = prompt(text: "changelog: ",/// submit changelog information multi_line_end_keyword: >>> Upload_to_testFlight (Changelog: Changelog) // Upload_to_testFlight (Changelog: Changelog) // Upload to TestFlight for testing eg: upload_to_testflight(changelog: "Add rocket emoji") eg: upload_to_testflight(skip_waiting_for_build_processing: true) skip the "Waiting for processing" of the binary While this will speed up your build, It will not distribute the binary to your tests, nor set a changelog You can run the following command to automatically generate ipA packets authorized by p12. >>>build_app("Sakura. Xcworkspace ") [project 1, Project 2] configuration: "Release", # Debug or Release clean: Export_method :"enterprise", # app-store, ad-hoc, package, enterprise, development, Developer-id output_directory: './build', # specify the directory output_name: "sakura. ipa", //export_xcargs: "-allowProvisioningUpdates", export_options: { provisioningProfiles: }}) >>> Enable_automatic_code_signing (path: "Sakura.xcworkspace") // Enable automatic signatureCopy the code

Fastlane add-on

1. Search for plug-ins by using the following command (default is in the current project directory, using FIrim as an example) :

$:fastlane search_plugins fir
Copy the code

The actual plugin to install is FIrim, so the search results will show multiple names of plugins with multiple FIRs. When firim is seen, you can anchor it (fir.im).

2. Add plug-ins

$:fastlane add_plugin  firim
Copy the code

In this step, the following error occurs:

An error occurred while installing UNF_ext (0.0.7.6), Make sure that 'gem install unf_ext -v '0.0.7.6'' succeeds before bundling.Copy the code

Comment the source of the Gemfile file.

3. Add plugin command in Fastlane

Upload IPA to fir.im server and obtain firiM_API_token from fir.im

firim(firim_api_token: '123456fdedftyuioopa9988hnai9')
Copy the code

If you upload to dandelion, you need to obtain api_key and userKey from dandelion.

pgyer(api_key: "2bd73d92030", user_key: "f0c61905ed")
Copy the code

5. Query more parameters

Can be used when parameters in a Known Ruby command are not functional

 fastlane action **** 
//such as 'upload_to_testflight', to get a list of all available options
fastlane action upload_to_testflight

Copy the code

Profile description file name corresponding to the current Scheme indicates the profile file that needs to be selected when the current project is not automatically configured during packaging.

When a project is released, there will be multiple Provisioning Profiles corresponding to the BundleID that are valid.

When selecting Automatically manage Signing, you need to CD to ~/Library/Mobile Device/profile to find a valid description file.

Multiple Provisioning Profiles exist if there are multiple Targets in a project. You need to define environment variables in the Fastlane file or manually switch to select Provisioning Profiles.