An inevitable part of iOS development is the torture of packaging during beta, whether it’s packaging to App Store Connect or a distribution platform like Dandelion. Especially during the test feedback phase, you can have to package a bug multiple times. Now use Fastlane to do it, achieve one-click upload.

Not to solve everyone’s practical application needs, not to do too much introduction, straight to the theme.

The installation of the fastlane

Fastlane can be installed in a variety of ways, as described on the official website.

Configuring Xcode

Xcode command line tools (macOS)

xcode-select --install
Copy the code

The installationfastlane

There are many ways to install Fastlane, but Bundler is officially recommended. Homebrew can also be used, although there may be some more intractable conflicts due to the dependency on the system’s Ruby environment. However, I chose to install it this way, after all, almost any problem can be solved on the web, if you like.

Managed Ruby environment + Bundler (macOS/Linux/Windows)

Ruby

This is officially not recommended, and Fastlane supports Ruby 2.5 and above.

Viewing the Ruby version

$Ruby -- Version Ruby 2.7.2 P137 (2020-10-01 revision 5445e04352) [x86_64-darwin19]Copy the code

Bundler

It is recommended to use Bundler and Gemfile to define fastlane dependencies. Fast fastlane execution by defining the version of Fastlane to use and its dependencies.

  • The installationBundler  gem install bundler
  • Create it in the project directory./GemfileFile, as follows
source "https://rubygems.org"

gem "fastlane"
Copy the code
  • runbundle update 将 ./Gemfile 和 ./Gemfile.lockAdd to version control
  • Used when running Fastlanebundle exec fastlane [lane]
  • Add it the first time you run it on your CI machinebundle installThe command
  • runbundle update fastlaneupdatefastlane

Homebrew (macOS)

This installation does not require a separate Ruby installation, homebrew will install the appropriate Ruby for Fastlane.

brew install fastlane
Copy the code

System Ruby + RubyGems (macOS/Linux/Windows)

sudo gem install fastlane
Copy the code

configurationfastlane

Execute in the project root directory

fastlane init
Copy the code

There will be some configuration related to the implementation including the Apple ID and password to be uploaded. One of the trouble with this method is that if you have secondary authentication enabled, the verification code will be sent through the reserved phone number, which is a bit more troublesome, so we don’t use this method.

The Fastlane folder will be generated in the directory

Fastlane /Fastfile is the file we will configure, which will be explained later.

Set the environment variables

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
Copy the code

Now that the basic installation configuration is complete, the Fastfile configuration is used to complete the packing and uploading work. Here is an example of uploading to App Store Connect.

Configuration falstfile

# Fastlane version fastlane_version= "2.199.0"

default_platform :ios


ENV["FASTLANE_XCODEBUILD_SETTINGS_TIMEOUT"] = "30"

ENV["FASTLANE_XCODEBUILD_SETTINGS_RETRIES"] = "20"



platform :ios do


    desc 'Deploy a new version to the App Store'# release' is the command used with Fastlane. 'Fastlane Release' is called to start execution with # options. Lane :release is not currently passeddo |options|# gym:Alias forThe 'build_app' action, build_app alias gym(# clean before packing:trueOutput_directory = 'output_directory';. /fastlane/Release ', # package name, replace with your own output_name: 'IPAName.ipa', # project scheme, change to own scheme:"yourproscheme", # defaultThe Release, the Release or Debug
        configuration: 'Release', # contains bitcode include_bitcode:true, # contains symbols include_symbols:true, # package export, including app-store, validation, ad-hoc, package, enterprise, development, developer-id and mac-application
        export_method: 'app-Store ', # this setting is used to set xcode to automatically configure certificates and configuration files, but it can also be manually configured. See export_xcargs: '-AllowProvisioningUpdates') # MAC popup for notification(app_icon: '. /fastlane/PNG ', title: 'manager', subtitle: 'Packaged successfully, exported installation package ', message:' Ready to publish...') # config uploadApp StoreConnect's API_key # allows one-click package upload of the API_key, bypassing validation operations such as secondary authentication=App_store_connect_api_key (# app_store_connect_API_key (# app_store_connect_API_key (# app_store_connect_API_key) # app_store_connect_API_key (# app_store_connect_API_key)/ / appleid.apple.com/account/manage the private keyKey_id: 'your key_id', issuer_id: 'your issuer ID ', # issu_filepath: '. /fastlane/AuthKey_yours.p8',

        duration: 1200,

        in_house: falseApi_key: api_key, skip_waiting_for_build_processing:true, # pack the files to upload ipa: '. /fastlane/release/IPAName.ipa',

        skip_submission: trueNotification (app_icon:"icon.png",title:"LoanManager",subtitle: "IPA uploaded successfully", message: "Autopack done!")

    

    end


end

Copy the code

Use the current command to package fastlane Release wait, but there may be different problems due to configuration issues, but the problem is not big, you can find the corresponding solution to fastlane issues on Github.

In addition to the current usage, there are version-related actions, such as one-click COMMIT


    desc 'git add . and git commit -m message'

    lane :commit do |options|

    message = options[:message]

    git_add(path:'.')

    git_commit(path: '.', message: message)

    UI.message("Complete commit")

    end
Copy the code

Simple Git add and Git commit operations, where a message can be passed via fastlane Commit Message: ‘Your commit message’ and can have multiple parameters.

These are simple operations that can be automated with more combinations, such as merge to master branch after commit and push to remote repository, etc. It is recommended to look at actions in the official documentation.

This article only does the entry study of use, the author is also a small white, hope we can exchange more common progress.