Automating Deployment of Android Apps Using Fastlane with CI/CD.

Jalan Technology Consulting
Jalan Technologies
Published in
4 min readSep 23, 2021

What Is Fastlane?

Fastlane is a great tool to automate your app deployment and release process for Android as well as iOS. It is responsible for handling tedious tasks like generating screenshots, code signing, and releasing your application

Installing and Setting Up Fastlane

Today we will be looking forward to the deployment of Android apps over CI/CD using Fastlane. Below are steps to achieve a successful Android Fastlane Deployment. This process has to be done locally in the source directory of your project, not over the CI/CD.

Installing Fastlane

On your CLI (Command Line Interface), navigate to your project folder and run the following command to install

sudo gem install fastlane

To verify that the installation was successful type the command:

fastlane -version

Setting up Fastlane

Navigate your terminal to your project’s directory:

fastlane init( It Initializes Fastlane )

and then you can follow the instruction here to configure the rest. After the successful setup, Fastlane will automatically generate a configuration file based on information. This process generates our App file and Fast file, in a directory Fastlane.

What Is AppFile?

Appfile is used to define a configuration that is global to the app. It contains information of where your package name and JSON secret key (path to Google Play Console) are.

What Is Fastfile?

Fastfile is the most interesting file as it has all the information that is needed to distribute the app. It defines different lanes that drive the behavior of Fastlane to perform different tasks. The group of steps defined in a fast file are called lanes. Examples: Tasks to run tests, assemble a debug build & upload your beta app to Crashlytics, deploy/upload a new version to Google Play, and so on.
For the creation of your Fastfile and Appfile, I will recommend you to check this out. Here you will get all the information on creating different tracks and running tests as well.

What Is Continuous Integration?

Continuous Integration (CI) is a development practice where developers integrate code into a shared repository frequently, preferably several times a day. Each integration can then be verified by an automated build and automated tests. While automated testing is not strictly part of CI it is typically implied- Codeship

Integration of Fastlane With CI/CD

Now comes the tricky part where you will like it to be more secure than ever before because you will be pushing the code to a git repository.
What’s worse than pushing a code with hard-coded values? Right! so you will want it to be more secure as it is going to be over the internet and is also considered a good practice. So whatever values are to be provided in the App file and Fast file, we will use Environment Variables to pass them while over CI/CD. Below is a snippet of how:

Now locally we can easily declare these variables and can deploy them to the play store but the challenge comes when it is on CI/CD as you need to create an environment that is suitable for the development of Android Apps, with required SDK’s and tools.
So, for that, we will use a docker image theanam/react-native, which I find certainly the best to get the task done.

Now with few things remaining the main challenge is to get those environment variables inside the docker container. This is pretty easy I guess follow the command below but first, you need to build the docker image as well:

docker run -it -e ENVIRONMENT_VARIABLE1=$ENVIRONMENT_VARIABLE1 -e ... -e ... DOCKER_IMAGE

Now as the project has been copied inside the docker and is ready to run simply define the ENTRYPOINT of the docker container in the Docker file as

ENTRYPOINT npm install && fastlane android beta

*beta is the name of the track in the Fastfile, so you can use the one defined by you and to be used.*

The only thing now left is configuring your CI file that is different for every CI/CD platform, but don’t forget to add those ENVIRONMENT_VARIABLES in your CI/CD platform.

The things you need to define in CI/CD file are building the docker image with your project inside it and then running that Docker Instance. Rest Fastlane will take care of and make sure your app is up and running for users.

Congratulations!
You have successfully implemented Fastlane with CI/CD and pushed the application to PlayStore.

Originally published at: https://articles.jalantechnologies.com/automating-deployment-of-android-apps-using-fastlane-with-ci-cd/

What’s the biggest thing you’re struggling with right now that we as a technology consulting company can help you with? Feel free to reach out to us. We hope our assistance will help!

--

--