Fastlane: Automate beta deployments and releases for your android apps

Milan Vadhel
Mindful Engineering
5 min readMay 17, 2022

--

Image by Mindinventory

As an android developer generating the build, uploading it to the firebase app distribution and notifying your beta testers whenever a new build is available for testing, or generating the screenshots for your app and releasing it to the Play store every time manually is a tedious task. Well doing the same thing, again and again, is ultimately time-consuming.

As software engineers, we should think out of the box and make something like a program that will do certain things which will eliminate developer intervention and save hours. Something like automation? But how? We need a solution that will build and upload our app to the Firebase/Play store by hitting just one command. To solve this problem Fastlane came to the rescue. Fastlane is an open-source platform aimed at simplifying Android and iOS deployment.

To Automate your beta deployment with Fastlane first we need to do some setup things. We will do it step by step here.

Image by Miro Medium Via

Note: Below Fastlane installation steps are for Ubuntu, you can check for your OS from here.

Fastlane installation steps :

(1) Run the “sudo apt update” command in your terminal

(2) Run the “sudo apt install ruby-full” command in your terminal

(3) Run the “ruby — version” command in your terminal to ensure that the ruby is installed with the correct version

(4) Run the “gem install bundler” command in your terminal

If you get any error then Run “sudo apt install ruby-bundler” command in your terminal

(5) Create a ./Gemfile in the root directory of your project with the below content :

(6) Run the “bundle install” command in your terminal which will add the Gemfile.lock in your project directory

(7) Run the “bundle update” command in your terminal

(8) Run the “sudo gem install fastlane” command in your terminal to install the Fastlane

Congratulations, we are done with the Fastlane installation setup!!

Now let’s perform some steps to set up your project for beta deployment :

(1) Run the “fastlane init” command in your terminal which will ask you to enter the package name of your app, and the path of the JSON secret file to communicate with the Play store(You can check the steps to generate the JSON secret file from here).

(2) Just follow the steps which are asked by the terminal.

By doing so, we will have a Fastlane directory with Appfile and Fastfile created.

Appfile: It contains the package name of your app and JSON file path which you can change later on if needed.

Fastfile: It contains required lanes to perform the steps like releasing your app to the Play store, firebase app distribution, etc.

Format to write lane for whatever operation you want to perform :

Now let’s make some lanes to beta deployment on the Play store.

Image by nikit19 Via

(1) Lane to deploy your APK file to the Play Store in the internal track

(2) Lane to deploy your bundle file to the Play Store in the internal track

As you can see we have added some parameters in the gradle and supply block which are described below:

Parameters in gradle :

Parameters in supply :

These are the parameters for Playstore configuration.

You can refer to more parameters from here

Now let’s make some lanes to beta deployment on the Firebase App Distribution.

Image by Ishara JesuHrz Via

Before that you need to install the firebase_app_distribution plugin via hitting the below command in your terminal :

fastlane add_plugin firebase_app_distribution

(1) Lane to deploy your APK file to the Firebase App Distribution.

(2) Lane to deploy your bundle file to the Firebase App Distribution

Parameters in firebase_app_distribution

You need to add your group name as the CLI group name. As shown in the below image you can get the group name from the Firebase console App Distribution section.

Generate your Firebase CLI token by following the steps mentioned below :

  1. Just hit “curl -sL https://firebase.tools | bash” command in your terminal to install the Firebase CLI on your local machine.
  2. Run “firebase login” command which redirects you to the browser to obtain access from you.
  3. Once you are done then run “firebase login:ci” command which will print the Firebase CLI token on your terminal.

As you can see I have uploaded the APK to firebase app distribution via Fastlane.

If you found this article useful then please share and don’t forget to give a clap. You can find the GitHub source here. Feel free to comment if you have any queries.

In the next article, we will cover Fastlane with Github Actions in a more advanced way to integrate automation into your project.

Till the time happy coding.

--

--