Android CI/CD with fastlane, Firebase App Distribution, and Bitrise

In this step-by-step guide, we will show you how to publish and distribute Android apps quickly and easily using fastlane, Firebase App Distribution, and Bitrise.

Important Note:

From August 2021, new apps will be required to publish with the Android App Bundle on Google Play. Read more about the Android App Bundle in the developer documentation.

What’s the Android App Bundle (AAB)?

The Android App Bundle (AAB) is a publishing format that includes all an app’s compiled code and resources, and defers APK generation and signing to Google Play.

Google Play uses the App Bundle to generate and serve optimized APKs for each device configuration, so only the code and resources that are needed for a specific device are downloaded to run the app. 

What’s Firebase App Distribution?

Firebase App Distribution makes distributing your app to testers quick and easy, allowing you to get feedback early and often. For more information about Firebase App Distribution check what’s new from Firebase at Google I/O 2021. 

With Firebase App Distribution you can distribute your Android app in several ways, such as Firebase Console, Firebase CLI, fastlane, and Gradle.

App Distribution integrates with Google Play's internal app sharing service to streamline your app testing and launching processes.

When you distribute AAB, you can:

  • Test app bundle features like Play Feature Delivery and Play Asset Delivery
  • Reduce the size of downloads for your testers.

In the Firebase console, you can see App Distribution in the side menu.You can upload your app for releases, specify testers and divide them into groups under the “Testers & Groups” tab, and create invitation links. 



You can upload your app for releases, specify testers and divide them into groups under the “Testers & Groups” tab, and create invitation links. 



What’s fastlane?

fastlane is an open-source platform aimed at simplifying Android and iOS deployment. It lets you automate every aspect of your development and release workflow, and it’s the easiest way to build and release mobile apps. 

Why fastlane?

  • fastlane’s automation tasks can save you hours, especially every time you push a new release to the store or beta testing service.
  • It integrates with more than 400 tools and services. 
  • It offers easy setup, runs on your machine, and integrates with all major CI systems such as Bitrise, CircleCI, GitHub Actions, and more.
  • It supports iOS, Mac, Android, and cross-platform apps like Flutter.

Getting started with fastlane

To install and configure fastlane on your local machine you can use Homebrew with macOS or Bundler, but before that, you should install and configure Ruby on your machine. 

fastlane supports Ruby versions 2.5 or newer. More about the setup can be found here.

Then you can initialize fastlane into your iOS or Android app using the following command:




After that, you will have a fastlane folder with a Fastfile in it. You can start adding your lanes for different tasks like running unit tests, UI tests, checking code style, deploying your app, and more. By default, you will find two lanes for submitting a beta build and deploying a new version to Google Play. 


How to add the App Distribution plugin into fastlane

The plugin system provides us with extra features and functions for fastlane to help us build, test, and deploy our mobile apps easily. 

You can add your preferred fastlane plugin by running the following command line: 

You will notice that a new file will be created inside the fastlane folder called Pluginfile.And also if you have Gemfile you add the plugin in this file to install it after that with the bundle. 



And also if you have Gemfile you add the plugin in this file to install it after that with the bundle. 

Before you begin with Firebase App Distribution you should:

  1. Add Firebase to your Android project.
  2. Connect your Firebase project to your Google Play account.
  3. Generate Firebase service account credentials with Firebase App Distribution Admin role.
  4. Generate the private JSON file for the credentials and keep this file in the root directory of your project.

And now we can add a lane using the App Distribution plugin like the following:


Testing it locally

To make the build available to testers, run your lane:

TIP: 

You can reference all the App Distribution parameters here.

If everything is working correctly then we are ready to automate with the CI/CD.

Bitrise and fastlane

With Bitrise, you can run your fastlane lanes with the same commands you would use locally. Bitrise’s automated Steps provide extra functionality to your lanes and speed up your builds.

Bitrise has an automated Step for running your lanes in the CI/CD pipelines — read the guide for Integrating fastlane into Bitrise.

NOTE: 

Once you set up your Android project with Bitrise, you need to add the Firebase service account and the Project ID as secret keys to be able to use it with fastlane.


And after that, you can add the Download Google Service Account Step, fastlane Step, and Slack Step to notify the testers and developers of the build status. 


Now we can trigger your build manually from the app dashboard and click on the Start/Schedule Build button and click the Start button. 

After the build has finished successfully, you can check your Firebase App Distribution dashboard for the new release. 

For more info about fastlane, check out these articles: Fastlane actions that make a developer’s life easier and Fastlane plugins that make a developer’s life easier.

Conclusion

Fastlane is one of the best tools for simplifying Android deployment. It’s the easiest way to build and release mobile apps and with actions and plugins, we have a variety of options we can use to speed our build and release processes.

Thank you for reading this article — stay safe and happy learning! 

Further Reading



Get Started for free

Start building now, choose a plan later.

Sign Up

Get started for free

Start building now, choose a plan later.