Gradle Managed Devices: The Future of Android Testing [Part 2]

Andres Sandoval
3 min readMay 21, 2023

Android Automation Testing with Gradle Managed Devices using Firebase TestLab devices

The new Android Gradle plugin helps developers run test on virtual/real devices. Testing Android applications as part of the CI process can get complicated, sometimes it’s hard to have a stable environment to run Android test automation. Google is helping developers with creating virtual Android devices to run your tests. With the new Gradle plugin you will write your test, then configure inside your file “build.gradle” which device you want your tests to run on. More details here Scale your tests with Gradle Managed Devices | Android Developers.

Goal

Run Android tests on cloud devices using Gradle managed devices and Firebase Test lab devices.

Prerequisites

  • Use the latest Android Studio (at this time Hedgehog canary version)
  • Use the latest Gradle managed devices is table in AGP (Android Gradle Plugin) 8.0.+

Steps

Run Gradle Managed devices using Firebase Test Lab cloud device locally from Android Studio.

  1. Open Android Studio.
  2. First we need to login to Firebase from Android Studio. Go to ->Help -> Firebase -> connect (sign in to your Firebase TestLab account)

3. Add the Firebase TestLab plugin to build.gradle(project):

plugins {
id 'com.google.firebase.testlab' version '0.0.1-alpha03' apply false
}

4. Add below to build.gradle(app):

plugins {
id 'com.google.firebase.testlab'
}

5. Then add Firebase Test Lab device configuration to build.gradle(app):

testOptions {
managedDevices {
devices {
device1(com.google.firebase.testlab.gradle.ManagedDevice) {
device = "Pixel2"
apiLevel = 30
}
}
}

6. Run the Gradle managed task to run Firebase Test Lab Run devices:

$./gradlew device1DebugAndroidTest

--

--