Fastlane Practise with Android and iOS (with examples)
Fastlane Features
"The easiest way to build and release mobile apps". Which handles the majority of the manual works
Fastlane has the following features:
- FREE
- Build Alpha/Beta/Production binary,
ipafor iOS,apkfor Android Automatically - Sign
ipausingApple Provision Filefor iOS Automatically - Sign
apkusingAndroid Keystorefor Android Automatically - Upload to
TestFlight,Google Play,FabricAutomatically - Work with multiple
build variants - More?Auto TestingVersion/Build Number automatically bump upIntegrated with
VSTSDefine your own home madefastlane actionby the needs
Install fastlane on Mac OSX
# Step 1. Install Xcode command line tool
xcode-select --install
# Step 2. Install fastlane
sudo gem install fastlane
How to use Fastlane in real life
Step 1: Run fastlane init under the root directory of the iOS/Android project. There will be a folder named fastlanecreated 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. And of course, you can use options for asking those credentials, the above example would be slightly different
# 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
gradleto clean previous build, create new builds, and sign with keystore. Signed apk will be generated in theoutputfolder. - line 19 – line 35: using
crashlyticsto upload aboved signed apk toFabric
Step 3: Simply at the root directory of the project run:
fastlane android buildNote: if you have used the options, at the stage of uploading, you are required to input keystore information.
Reference
Fastlane: https://fastlane.tools/