Hi, everyone.
I'm Michael Hazard, a product manager
on the Android Developer Tools team.
Today, I'll show you how Android Studio's making it easier than ever before
to test your app's compatibility across a wide variety of API levels
and form factors.
Android's ecosystem diversity allows developers to reach a ton of users,
but it also presents a challenge.
Developers need to make sure their app looks the best,
regardless of the device running it.
This could be making sure an app looks good on phones,
tablets, and large screen devices.
Maybe also making sure an app runs perfectly
across Android's different API levels.
Testing across a wide variety of API levels and form factors
is the best way to ensure that all users have a great experience.
Usually, this is done manually by QA,
or during automated pre and post-submit integration testing.
Testing during development allows you to catch bugs before QA,
and, more importantly, before they impact your users.
Starting in Android Studio 4.2, instrumentation tests can be run
across multiple physical or virtual devices in parallel.
The outcomes can be investigated
using a new instrumentation test results panel.
This flows design helps you identify failures caused by differences
in API level or form factor as early as possible.
To get started, we need to select a set of devices
to run our tests.
A good device set is representative of your app's user base
so start by checking out your Play Console Statistics dashboard
to see the API levels in devices most frequently used
to run your app.
You can even look at which API levels or devices result in the most crashes.
If you're testing the impact of API level,
it's a good idea to choose devices running your app's minSdkVersion
and targetSdkVersion.
It's also good to include your compileSdkVersion
in the most recent version of Android.
When testing the impact of form factor,
select devices with a variety of display resolutions,
densities, and features.
For the sake of this example,
I'll go ahead and test my app
to make sure it's compatible with the latest release of Android,
which as of this recording is Android 11.
I've already set up devices that are on API level 23
my minSdkVersion on API level 28, my targetSdkVersion.
Now, I'll go ahead and create a virtual device
that runs Android 11.
My existing devices are Pixel 3's,
so I'm going to go ahead and make my new device a Pixel 3,
which ensures that any new failures are due to the difference in API level,
not differences in form factor.
Now that all my devices are ready,
I'll go ahead and select Modify Device Set.
This opens a dialog, which allows me
to select the devices I'd like to run my tests on.
As I mentioned before, I'll select my API level 23, 28, and 30 devices.
Clicking OK in this dialog creates a persistent device set.
This device set could be targeted by selecting multiple devices.
After I've made this selection, I can run my tests as usual.
Upon hitting Run,
Android Studio will automatically boot any virtual devices in my device set,
install my APK, and execute my tests.
Test results are then displayed in the Run panel
and streamed in as execution completes.
As you can see here, this new Test Results panel
provides one row for each of my tests and one column for each of my devices,
which allows easy side-by-side comparison of results.
Using this, I can quickly identify tests that failed
based on API level or form factor.
If you have lots of tests, you can also use this to sort
and filter results to find what you're looking for easier.
Here, it looks like my test is failing on API level 30,
also known as Android 11,
but passing on API level 28.
To get to the bottom of why this test failed,
I'll click on the corresponding row
to see logs broken out by device.
I can also use my new device set to run my app
and visually check for any errors.
This is especially useful when testing different form factors.
By using Android Studio, you can make testing compatibility
across devices part of your regular workflow.
We'd recommend doing this as often as possible,
as it'll allow you to catch and fix bugs prior to integration,
which will save you time
and ultimately make it easier to produce a high quality app.
Thanks for watching, and happy testing.