How to simplify Android app distribution with Fastlane and improve workflow?
Senior Software Engineer - 18 March 2021 -
Senior Software Engineer - 18 March 2021 -
Making releases, taking screenshots, and updating metadata in Google Play Store are all facets of Android app growth. But you can automate these to save time for meaningful things like integrating functionality and repairing bugs.
Fastlane lets you do all that repeatedly and effectively. It’s an open-source tool that makes Android and iOS software distribution simpler. It helps you simplify any part of the workflow for creation and publication.
In this blog, we’ll learn how to use Fastlane to distribute an app on the firebase app distribution platform and add testers to test the build.
We will use our BLE Scanner app (you can read more about this app here) to automate a few tasks.
Take checkout of the project and make sure it is working fine, you can build it and run it on a device.
There are many ways to install Fastlane, for more details visit here.
We will install it using Homebrew
brew install fastlane
Open the terminal and navigate to your project directory and then run the following command.
It will ask you to confirm a few specifics.
You’ll get a couple more prompts after that. To proceed, click Enter. When you’re done, run the following command to test the new fastlane configuration:
After successfully running the ‘test’ command you will see something like below.
The following files can be found in the newly created `fastlane` directory:
Appfile: that specifies configuration data for your android app that is global
Fastfile: that specifies the “lanes” that govern how fastlane acts.
To store the automation setup, Fastlane uses a Fastfile. When you open Fastfile, you’ll see the following:
Fastlane splits multiple acts into lanes. A lane begins with lane: name, where the name of a lane is the name given. You can see three separate lanes inside the file: test, beta and deploy.
The following is a list of the actions that each lane performs:
Let’s edit Fastfile and add a new lane to clean build our app.
To add a new lane we have to edit `platform :android do`
Add lane cleanBuild by adding something like below.
Open the terminal and run the following command
You will get the following message after successful execution.
Now this tells us how we can create a lane and how to use that. Let’s Automate beta app distribution using firebase app distribution
Once you are done with a new feature, you’ll want to share it with beta testers or your QA to test the stability of the build and gather feedback before releasing it on the Play Store.
For this kind of distribution, we use the highly recommended Firebase app distribution tool.
To use any of the firebase tools in our app we need to have a firebase project for it. Let’s create the one for our BLE Scanner App
Fastlane needs FirebaseCLI to connect to the Firebase server for uploading the build.
Run the following command in terminal
fastlane add_plugin firebase_app_distribution
Select `Y’ for the prompt `Should fastlane modify the Gemfile at path`
You’re now ready to submit various versions of the app to different groups of testers using Firebase.
Open Fastfile and overwrite the beta lane with the following, replacing the `app` with the App ID you copied earlier:
The whole Fastfile will be looking like this
Replace YOUR_APP_ID and YOUR_GROUP_NAME with correct values.
After editing Fastfile run the following command on the terminal.
After the successful execution of the above command, you will see something like below.
The tester would receive email notification for Build.
You can also see the Firebase console to verify whether the new build is uploaded with release notes and testers have been added to the same or not.
We can have multiple flavors of our app depending upon different criteria, we can have different flavors for different environments like production, staging, QA and development.
To run a specific flavor we can run the following command
fastlane beta app:flavorName
Here flavorName can be prod,staging,qa,dev
If you provide a flavor with an app key, Fastfile will run gradle assembleReleaseFlavor. Otherwise, it will run gradle assembleRelease to build all build flavors.
We have successfully automated the task of building an android app and distributing it to QA, now it’s as simple as one command execution “fastlane beta” which can be done by any non-technical person as well.
For more details and an in-depth view, you can find the code here