Fastlane Practise with Android and iOS

Fastlane

Fastlane

“The easiest way to build and release mobile apps”. fastlane handles the majority of the manual works, which sig including the following features:

  • FREE
  • Build Alpha/Beta/Production binary, ipa for iOS, apk for Android Automatically
  • Sign ipa using Apple Provision File for iOS Automatically
  • Sign apk using Android Keystore for Android Automatically
  • Upload to TestFlight, Google Play, Fabric Automatically
  • Work with multiple build variants
  • More?
    • Auto Testing
    • Version/Build Number automatically bump up
    • Integrated with VSTS
    • Define your own home made fastlane action by the needs

Installation on Mac

# Step 1. Install Xcode command line tool
xcode-select --install
# Step 2. Install fastlane
sudo gem install fastlane

Usage

Step 1: Run fastlane init under the root directory of the iOS/Android project. There will be a folder named fastlane created with two files in:

fastlane
├── Appfile
├── Fastfile
File
Fastfile Defines all your necessary steps & behaviours you want to automise, such as build, sign, upload and so on
Appfile Defines some properties of the app, i.e. if you have multiple build variants

Step 2: Example of the Fastlane

Take the Android project for example. Both Android and iOS fastlane example here:

# Fastlane with keystore
default_platform(:android)
platform :android do
lane :build do
gradle(task: "clean")
gradle(
task: 'assemble',
build_type: 'Release',
#flavor: 'com.sunsuper.acpt',
properties: {
"android.injected.signing.store.file" => "/Users/ben/ben_ws/certs/Android/SunsuperAndroidKeyStore.jks",
"android.injected.signing.store.password" => "[storepassword]",
"android.injected.signing.key.alias" => "[keystore alias]",
"android.injected.signing.key.password" => "[key password]",
}
)
crashlytics(
api_token: '[api token]',
build_secret: '[build secret]',
apk_path: "yourpath/apk/app-integ-release.apk"
)
crashlytics(
api_token: '[api token]',
build_secret: '[build secret]',
apk_path: "yourpath/apk/app-acpt-release.apk"
)
crashlytics(
api_token: '[api token]',
build_secret: '[build secret]',
apk_path: "yourpath/apk/app-prod-release.apk"
)
end
end

Keystore file, Keystore password and Key password are not recommended to put into Fastlane file. You can use options for asking those credentials.

# Fastlane without keystore
default_platform(:android)
platform :android do
lane :build do |options|
gradle(task: "clean")
gradle(
task: 'assemble',
build_type: 'Release',
#flavor: 'com.sunsuper.acpt',
properties: {
"android.injected.signing.store.file" => options[:storefile],
"android.injected.signing.store.password" => "[storepassword]",
"android.injected.signing.key.alias" => "[keystore alias]",
"android.injected.signing.key.password" => "[key password]",
}
)
crashlytics(
api_token: '[api token]',
build_secret: '[build secret]',
apk_path: "yourpath/apk/app-integ-release.apk"
)
crashlytics(
api_token: '[api token]',
build_secret: '[build secret]',
apk_path: "yourpath/apk/app-acpt-release.apk"
)
crashlytics(
api_token: '[api token]',
build_secret: '[build secret]',
apk_path: "yourpath/apk/app-prod-release.apk"
)
end
end

Line 5 – line 36 are our self defined lane named build which includes:

  • line 6 – line 17: using gradle to clean previous build, create new builds, and sign with keystore. Signed apk will be generated in the output folder.
  • line 19 – line 35: using crashlytics to upload aboved signed apk to Fabric

Step 3: Simply at the root directory of the project run

fastlane android build

if you have used the options, at the stage of uploading, you are required to input keystore information.

Todo

Reference

Fastlane: https://fastlane.tools/

About: arkilis


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.