Distribute app bundle releases to testers - Codelab

1. Overview

image10.png

In this codelab, you'll learn how to distribute Android App Bundle releases to testers using Firebase App Distribution and its Gradle plugin. App Distribution provides a central hub for you to manage pre-release versions of your app and the testers you invite to each release.

What you'll learn

  • How to link your Firebase app to Google Play
  • How to package and build your app as an app bundle
  • How to create a release and share it with live testers
  • How to download and test new releases as a tester

What you'll need

  • Android Studio v4.0+
  • A signed bundle file that you generated from Android Studio
  • A Google Play developer account for which you're the Owner or Admin
  • Your app in Google Play is setup on the Google Play app dashboard, and it has the following status:
    • The app is in a published state, meaning that it's not in Draft and its review is complete (the Update status column in the Google Play Console is empty).
    • The app is distributed on one of the following Google Play tracks: internal testing, closed, open testing, or production.
  • An email address you can use as a tester to receive new build invitations from Firebase

2. Create a Firebase project

  1. Sign in to Firebase.
  2. In the Firebase console, click Add Project, then name your project "AppBundlesCodelab." Remember the Project ID for your Firebase project. If you don't edit the Project ID, Firebase automatically assigns a unique ID for your project.

    image8.png
  3. (Optional) When prompted, enable Google Analytics.
  4. Complete the remaining steps, then click Create project.

Add your app bundle to the project

  1. In the Firebase console, click Add app.

    image5.png
  2. When registering your app, make sure to use the same package name as the app that's uploaded to your Google Play developer account. Finally, click Register app.
  3. Complete the remaining steps to add your app's Firebase configuration file (google-services.json) to your app. Note that for Android, App Distribution doesn't have a Firebase SDK to add to your app.
  4. Click Continue to console.
  1. In the Firebase console, go to your Project settings.

    image2.png
  2. In the Integrations tab, click Link on the Google Play card.
  3. Follow the on-screen instructions to enable the App Distribution integration, then select your newly created Firebase app to link to Google Play.

Now that you've completed these steps, your Firebase app will be linked to your app in your Google Play developer account as long as the apps' package names match.

3. Add App Distribution to your project

Add the App Distribution Gradle plugin

Now, you'll use Android Studio to add App Distribution and its Gradle plugin as buildscript dependencies to your app.

  1. In your project-level Gradle file (android/build.gradle), add the App Distribution Gradle plugin and Google's Maven repository.
    buildscript {
        repositories {
            // Check that you have Google's Maven repository (if not, add it).
            google()
            jcenter()
        }
        dependencies {
            // Add the App Distribution Gradle plugin
            classpath `com.google.firebase:firebase-appdistribution-gradle:2.1.2`
        }
    }
    
  2. In your app-level Gradle file (android/app/build.gradle), add the App Distribution plugin:
    apply plugin: `com.android.application`
    
    // ...
    
    // Apply the App Distribution Gradle plugin
    apply plugin: `com.google.firebase.appdistribution`
    
    // ...
    
  3. If you're behind a corporate proxy or Firewall, add the following Java system property that enables App Distribution to upload your distributions to Firebase:
    -Djavax.net.ssl.trustStore=/path/to/truststore -Djavax.net.ssl.trustStorePassword=password
    

Authenticate your Firebase project

Before you can use the Gradle plugin, you'll need to authenticate your Firebase project. For this codelab, you'll sign in to your Google account using the plugin's login action.

  1. Run the following command at the root of your Android project:
    ~/your-android-project$ ./gradlew appDistributionLogin
    
  2. When the command prints an authentication link, open it in a browser. When prompted, sign in to your Google account and grant permission to access your Firebase project. The Gradle command prints a refresh token, which the App Distribution plugin uses to authenticate with Firebase.
  3. Set the environment variable FIREBASE_TOKEN to the token from the previous step:
    ~/your-android-project$ export FIREBASE_TOKEN=your_firebase_token
    

4. Configure your bundle properties in Android Studio

In this step, you'll add yourself as a tester for the build you'll distribute later. Once you distribute the build, testers get email notifications from Firebase inviting them to test the new build.

In your app/build.gradle, add a firebaseAppDistribution section and include the following parameters:

  • appID: Your app's Firebase App ID. You can find it in the General tab of your Project settings.
  • artifactType: Your app's file type (AAB).
  • testers: Your testers' email addresses. For this codelab, add your own email so you can test your build once it's distributed.

For example:

android {

   // ...

   buildTypes {
       release {
           firebaseAppDistribution {
               appId="yourAppId"
               artifactType="AAB"
               testers="your@exampleemail.com, cerseimartell.772371@email.com"
           }
       }
   }

// ...
}

As an option, you can also override the values set in your build.gradle by passing command line arguments in the form of -PappDistribution-property-name=property-value.

5. Build and distribute a release

  1. Run the bundleVariant Gradle task to build your app bundles file:
    $ ./gradlew :base:bundleRelease
    
  2. Locate the bundle in your application's build directory (the default location is app/build/outputs/bundle/release).
  3. To distribute the release, build the targets bundleRelease and appDistributionUploadRelease with your project's Gradle wrapper. Include the Firebase token (the one you received in step 3: Add App Distribution to your app).
    export FIREBASE_TOKEN=your_firebase_token
    
    ./gradlew --stop // Only needed for environment variable changes
    
    ./gradlew bundleRelease appDistributionUploadRelease
    

Testers will now receive email invitations to download and test the build. As the developer, you can now monitor the build in the Releases tab of the App Distribution dashboard.

6. Download and test your release

In this section, you'll get set up as a tester in order to download the release you distributed. As a tester, you'll need to authenticate your test device and enable internal app sharing in the Google Play Store app.

  1. On your test device, sign in to your tester email account and open the invitation from Firebase.

    image6.png
  2. Sign in with your Google account and accept the invitation to test the distributed release. As an option, you can also download Firebase App Tester, which prevents downloaded releases from being added to your device's Downloads folder. It also displays additional information about releases, such as the download progress and release version.

    image9.png
  3. Tap Download on the release to install it from the Play Store.
  4. When prompted, complete the remaining steps to enable internal app sharing (the instructions are displayed on your test device and only need to be completed once).

Once the download is complete, your release will automatically appear as a shortcut in your device's home screen.

7. Congratulations!

You just used Firebase App Distribution to upload an app bundle and distribute a release to testers.

Next steps