Publishing to the Google Play Store with Fastlane and GitHub Actions

Akshat Tiwari
4 min readJan 26, 2022

--

In this article, we’ll learn to automate tasks for deploying our Android App to the Google Play Store using Fastlane and GitHub Actions.

Why Fastlane?

  • Fastlane is the easiest way to automate beta deployments and releases for your iOS and Android apps. 🚀
  • It handles all tedious tasks, like generating screenshots, dealing with code signing, and releasing your application.

You can tag along the following steps to do this setup.

Generating Google Play Credentials

  • Open the Google Play Console
  • Go to Settings → API Access → Click ‘Create new service account’ and follow steps mentioned in a dialog.
  • In GCP console, Click ‘➕CREATE SERVICE ACCOUNT’
  • Provide service account name → Click ‘Create’
  • Then select role ‘Service Account User’ and click ‘Continue’.
  • Next step is optional so click ‘Done’.
  • Then you’ll see list of service accounts, Click Action menu of service account which you just created → Create Key → Select ‘Key Type’ as ‘JSON’ → Click ‘CREATE’
  • Then the credentials file will be downloaded to your machine. Keep that file safe.
  • Come back to the Play Console → Click ‘DONE’ on dialog. You’ll see service account which you just created.
  • Click “GRANT ACCESS’ → Select application which you want to allow to publish → Make sure you’ve checked ‘Releases’ section.
  • Finally, click ‘Apply’ → Click ‘Invite User’
  • Thus you’ve successfully set up Google play credentials. Keep that file with you and keep it safe.

Setup Fastlane in app

  • Copy the Credentials JSON file which is downloaded in the previous step in the root directory of your project and give it name (For e.g. play_config.json)
  • Then just run a command — sudo gem install fastlane
  • Setup Fastlane using command — fastlane init and provide information with respect to your app.

Now you can see the newly created fastlane directory in your project with the following files

  • Appfile — Defines configuration information that is global to your app
  • Fastfile — Defines the "lanes" that drive the behaviour of Fastlane

Let’s create lanes

You can declare various lanes in Fastfile which can have different behaviours or simply we can call them tasks.

Setup GitHub Actions

As you might know that we always require a Keystore file (.jks)for signing APK/App Bundle before publishing app to the Google Play. You will also need Google play credentials file (.json) for deploying with Fastlane. If your project is in the private repository then you can easily include these files in VCS. But what if your project is opensource and you still you want to keep it secret? 🤔

Here GitHub Actions Secret comes to rescue 😃. Because we’ll store file contents in the Action Secrets. But we can’t directly store exact content because it may contain whitespace. So we’ll encode these files with Base64

For example. Run command 👇

base64 -i play_config.json > play_config.json.b64

This will encode Google play configuration file and see generated .b64 file. Now copy the content of the file and add a secret in GitHub Actions 👇.

Do the same procedure for the Keystore file and add Keystore file’s Base64encoded content and other configurations as secret. Now secrets of Action would look like 👇

Let’s create GitHub Action’s Workflow👨‍💻

  • Create a workflow file releaseProd.yml in .github/workflows directory. Add initial contents to the file as 👇

This means, whenever commits are pushed on to the prod branch, the deployment will be triggered. Also, setup Ruby for workflow.

  • Install Ruby bundle
  • Now let’s create Keystore (.jks) file and Google play configuration (.json) file from content which we created using GitHub Actions Secret.
  • Finally, let’s execute the PROD lane

Yeah! That’s it. You can do the same for the production deployment as per your choice.

Now just push some commits to the prod branch and see the magic

Wonderful! 🎉 Now your app is successfully deployed to the Google Play Store.

Write some code👨‍💻, push 🚀 and chill! 😎

I hope you liked this article. If you find this article helpful then share it with everyone. Maybe it’ll help someone who needs it 😃.

Feel free to connect with me on LinkedIn and check out my GitHub profile.

Thank you!

--

--

Akshat Tiwari
Akshat Tiwari

Written by Akshat Tiwari

Coding Geek, Open Source Enthusiast.

No responses yet