Automating Publishing Android App on firebase and Play store

I have been developing the application for more than six years and after finishing off one feature I have to give that build to QA to test out that feature. Instead of doing manually, it should be automatic pushing to distribute the channel of firebase or testing channel(alpha/beta/prod) on the play store for QA to check new features.
So, In this article we will go through how to push app using Fastlane or Github Actions, you can choose any one option as per your requirements.

Fastlane

  • You can check Fastlane here.

GitHub Actions

  • You can check Github Action here.

Let's start the process,

Step 1

We need to create a service JSON file from the Google play store to create a service account to give access to CI to push the app directly on the play store.

  • Go to Google Play Console
  • Create a private key for this service account and save this as JSON. and save this for later use, we need this at the time of CI setup.

Github Actions

Now the main part, we have play_config.json and we need the JKS file to signed an apk/aab and Keystore password and alias for that JKS file.

Github gives us options to save all this sensitive information in Github Secrets that can be accessed by the author, so you don’t need to worry about privacy. But there is one twist, we can’t upload it directly. we need to convert all of these files into Base64 string. So, CI can easily read it and not to worry about any spaces and special characters mapping. For this just run the below command with your file name and output file name.

base64 -i your_key_file.json > output_file.json.b64

Now go to settings > secrets and add this base64 text into the Github repository.

Now we need some other details into secrets, like

  • Keystore file (JKS)

We need all of the above, which can be used for pushing app on google play console and firebase app distribution.

For Firebase token follow these steps for FastLane distribution

Now we have a whole setup for GitHub actions prerequisites, now let's create a workflow for pushing the app through.

Create a .github folder in root repo and workflows folder inside that.

Create a release.yml file.

Now let’s discuss the above files:

push: branches: — release

The above line means our GitHub action will trigger when we push code on a release branch and the whole workflow will run. and other steps are like first we need env setup to get all secrets from Github secrets and load into env.

After environment in Github action build, clone that repo in action bots and signed app and build aab file using below command

./gradlew :app:bundleRelease

After successful of this run, we will get an aab file in-app release folder which we will use to upload the app on artifact and upload that same to play store using service account JSON.

If you noticed, I have added a slack webhook also, to notify the team that your CI pushed the app successfully.

You can refer to docs here

Now we need to push the app on firebase distribution, you can refer to the below gist, we just need to remember about APP_ID, CLI Token

Fastlane

Setup of FastLane is too easy, you can refer from the docs also based on your machine OS.

Fastlane supports Ruby, so we need a min 2.4 version of that and just run the below commands to setup that, or you can use homebrew. I am using homebrew here.

First, navigate to your folder in terminal/CMD for running this command.

brew install fastlane
fastlane init

After running the above command you will be asked some basic information about an app like app name, package name. we can skip it for later, or can provide it here. It’s not mandatory for now.

Keep that key JSON file that we have downloaded from the GCP platform in your root folder name play_config.json

After successfully initialized Fastlane, you will see two files inside fastlane the folder.

  1. Appfile - Application configuration like package name and all.
Appfile Information
Fastfile Information

The above two images have information about Appfile where we will define the app package name and the fastfile contains the lane which will be used to run our lane that can be releasing the app to firebase or play store.

We can also add multiple lanes to define our specific lane and run the command from the terminal fastlane distribute or fastlane beta

fastlane lanename

If you like this article, please share it with others and give 1,2,3 … claps.

Thank you!

Android Developer, Freelance, Enthusiastic Learner

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store