Developing for Android 11 with the Android Emulator

Michael Hazard
Android Developers
Published in
5 min readJul 30, 2020

--

We built the Android Emulator to make it possible for you to test your app without having to maintain a fleet of physical devices. While this is still our primary goal, we’re not satisfied with providing a tool that is exclusively an imitation of a physical device. Instead, we want to build an emulator that complements physical devices by providing features that are only made possible by a virtual device.

In the past, we’ve released features like the Location and Battery extended controls, both of which allow you to quickly test scenarios that would cause headaches on a physical device. The Location controls allow you to test your app’s reaction to movement along a route from the comfort of your desk, and the Battery controls allow you to test the impact of things like charge level state without having to wait for your physical device’s battery to run down.

The Location controls allow you to emulate movement along a route.

Today, I’d like to show you some of the new ways the Android Emulator is making it easier to develop and test your app, with a particular focus on functionality that aligns with new features in Android 11.

Foldables and other form factors

Unlocking the potential of foldable phones just got easier with Android Emulator version 30.0.23+, which can be found in the Android Studio Canary release channel. It features a new 3D foldable device rendering and expanded foldable controls. The 3D rendering makes it straightforward to visualize how your app will look on a foldable device, while the expanded controls allow you to explicitly set the angle of each fold or the overall device posture. You can use these additions to validate that your app looks great on foldable devices and build custom experiences that play off of the form factor’s strengths.

Using the Emulator to build an interface that splits into a parent child layout when the device’s state is HALF_OPENED and returns to normal when the state is OPENED.

This feature takes advantage of the flexibility of the Android Emulator and hooks directly into the WindowManager, a recent addition to Android Jetpack that makes it possible for developers to build consistent experiences that react to the posture of foldable devices. With these controls, you can explicitly set the WindowManager’s DeviceState and test your app’s reaction. In the example above, the Android Sunflower sample app has been modified to split into a parent child layout along the device’s hinge when the posture is HALF_OPENED, using the hardware to support novel UX. If you want to learn more about this library and building for foldables, read Building apps for foldables or Support New Form Factors with the New Jetpack WindowManager Library. If that’s not enough, look out for more content in the 9th week of 11 Weeks of Android: Android Beyond Phones.

Alongside the visualization and extended controls, we are expanding upon the two initial foldable hardware profiles and will be releasing profiles that feature horizontal folds and dual displays alongside Android Studio 4.2. Until then, or afterwards if you would like to customize your virtual device, foldable properties can be added or modified by editing a virtual device’s config.ini file. This makes it possible to emulate any foldable device on the market or even configurations that don’t yet exist. A virtual device’s config.ini file can be found by right clicking the device in the Android Virtual Device (AVD) Manager in Android Studio and selecting “Show on Disk”. Adding the following code to a Pixel 3’s config.ini file allows you to see what it would look like with a horizontal fold!

Additions to a virtual Pixel 3’s confing.ini that enable the foldable controls.
A virtual Pixel 3 with an added horizontal fold.

Keep in mind that foldables are only one of many alternative form factors supported by Android and the Android Emulator. Our Android Auto, Android TV, and WearOS virtual devices also make it possible to build for alternative form factors and reach even more users.

5G

The Android Emulator now features 5G support, allowing you to develop experiences that leverage 5G without having to purchase hardware or access a physical 5G network. To try this out, download and create a virtual device with one of the Android 11 Beta 2+ (API level 30) system images and run it with the latest version of the Android Emulator, which is available in the Android Studio Canary release channel.

The Android Emulator 5G network setting integrates with the new Android 11 5G detection, meteredness, and bandwidth estimation APIs, making it possible to develop for and test against this API surface with the click of a button.

The 5G network setting can be accessed in the Android Emulator’s Cellular controls

Check out our 5G documentation to learn more about adding 5G capabilities to your app.

Conclusion & Looking Forward

The Android Emulator was initially built to provide a realistic virtual device that makes it possible to test your app on every device configuration out there without having to upkeep a fleet of physical devices. We are still committed to this goal and will continue to provide a variety of device form factors alongside high quality, Android Compatibility Test Suite (CTS) compliant system images for each Android platform release.

That said, we aren’t satisfied with just providing the basic feature set of a physical device. Instead, we are also focused on building a tool that goes above and beyond, complementing physical devices with features that are only possible on a virtual device. The new Android Emulator foldable and 5G features are two examples of how the Android Emulator complements physical devices, and we hope that they help turn your app up to Android 11.

--

--