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.
- You can check Fastlane here.
- Fastlane provides code signing, releasing an app to play store, push an app to firebase app distribution or you can also generate screenshots by commands only.
- You can check Github Action here.
- Github action is the same as Fastlane helps you to push the app on the play store directly and also on firebase distribution.
Let's start the process,
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
- Go to Settings -> Developer Account > Api Access and Create a service account
- Open google console and create a service account for CI
- Add Permission
Service Account Useras per the below images.
- 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.
- After the success of this key generation (save as play_config.json), come back to the play console and click done, you will see one service account with the same name which you have given in the above step.
- Grant Access to that service account and check all section of releases and add your application which you want to use for this CI/CD.
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)
- Key alias
- Key password
- Store Password
- Firebase App Id (For firebase distribution)
- Firebase token (CLI token)
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
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
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
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
After successfully initialized Fastlane, you will see two files inside
fastlane the folder.
- Appfile - Application configuration like package name and all.
- Fastfile - It will contain lanes that will be used to push the app.
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
If you like this article, please share it with others and give 1,2,3 … claps.