Emulator control for adaptive app development
In a recent Android Developers post, Rob Orgiu, a Developer Relations Engineer on the Adaptive Apps squad, walks through a set of terminal shortcuts that let developers manipulate a virtual foldable device without opening the UI controls. By invoking adb emu fold or adb emu unfold the emulator instantly switches between its closed and opened states, while adb emu rotate spins the screen 90 degrees. The same pattern applies to sensor‑driven postures—listing supported positions with adb emu posture and selecting one by its numeric ID—and to the Resizable AVD’s preset sizes via adb emu resize-display. The guide also mentions targeting a specific emulator instance with ‑semu and the device’s serial number, a handy tip when several AVDs run side‑by‑side. This command‑line approach eliminates the overhead of launching separate emulator windows for each configuration, streamlining the iterative workflow that adaptive‑app developers rely on.
The push toward scriptable emulator control aligns with Google’s broader strategy to make Android a first‑class platform for foldable hardware. Pixel Fold and the generic Resizable AVD are the only official templates that expose three posture IDs (closed, half‑opened, opened), reflecting the limited but growing hardware ecosystem. By exposing these controls through adb, Google gives developers a Linux‑style automation layer comparable to Apple’s xcrun simctl for iOS simulators, narrowing the tooling gap that has historically favored iOS for rapid UI testing. Moreover, the fire‑and‑forget nature of the commands reduces CPU and memory pressure on developer machines, a practical benefit as Android Studio’s emulator already consumes substantial resources.
While the new shortcuts accelerate testing, they also surface a few caveats. Because posture support varies by AVD, scripts that assume a full set of IDs will fail on devices that lack certain configurations, returning “KO: Failed to set posture error.” Additionally, the emulator’s behavior may not perfectly mirror real‑world hinge mechanics, so developers must still validate on physical foldables before shipping. Finally, reliance on command‑line automation could obscure UI‑level issues that only appear when interacting with the emulator’s toolbar, so a balanced mix of scripted and manual testing remains advisable.
Key Takeaways
Developers can now toggle foldable states, rotate screens, change postures, and resize displays with single adb emu commands, removing the need for multiple concurrent emulators.
Targeting a specific virtual device via ‑semu and its serial number enables precise automation when several AVDs run simultaneously.
The feature brings Android’s emulator automation closer to iOS’s simulator tooling, supporting Google’s push for foldable‑first app design.
Scripts must account for the limited posture sets of each AVD and still include real‑device verification to avoid emulator‑only blind spots.
About the Source
This analysis is based on reporting by Android Developers. Here is a short excerpt for context:
Posted by Rob Orgiu, Developer Relations Engineer, Adaptive Apps, Android Adaptive app development is fundamental on Android, but making sure everything looks good and every feature works the way it should require multiple tests on multiple devices. Or does it? Well, yes… and no! While Android Studio is bundled with the Resizable Emulator to let you test layouts manually, there’s a faster, more streamlined way to control form factors directly from your terminal. By leveraging fire-and-forget console commands using the adb emu shortcut, you can execute commands that immediately return control to your invoking shell. If you have multiple emulators running at the same time, you can target a specific virtual device by passing in the shortcut's serial: adb -semuFirst things first: Fold and unfold To test foldable-specific user journeys and layout configurations, you can fold and unfold your emulated device programmatically. adb emu fold If your foldable emulator is unfolded, you can fold it to display its smaller screen configuration, powering on the (virtual) external display. To unfold the emulator and power on the internal display, simply run: adb emu unfold Now, you can instantly verify that your app preserves its state and that layouts appear exactly as they should on different display sizes. Rotation, rotation, rotation Correctly handling orientation changes is a cornerstone of adaptive app development. You can trigger device rotations programmatically to test how well your app handles configuration changes, including state restoration. The following command rotates the device 90° clockwise: adb emu rotate Simulating postures using sensors What about placing the emulator into a specific physical posture, like tabletop mode? The easiest approach is querying for the number of available positions with . First, list all available sensors and their current status: adb emu posture This returns a list of positions similar to the following: Usage: "posture" 1: closed 2: half-opened 3: opened … You can then invoke the tabletop posture by using the half-opened ID: adb emu posture 2 Note: Not all postures are supported by every virtual device. Standard AVD templates like the Pixel Fold or the Resizable AVD only support postures 1 , 2 , and 3 . Attempting to set 4 or 5 on these templates will return a KO: Failed to set posture error. What about the resizable emulator? The resizable emulator has the super power to change its size with ease. With the adb emu command, you can move it freely with one command. Before you can do any changes, querying for the available resize presets requires only one call: adb emu resize-display This will return the list of available presents: KO usage: "resize-display" 0: phone 1: unfolded 2: tablet Now, invoking the resize-display parameter with the wanted ID will resize the emulator to the wanted size: adb emu resize-display 1 Streamline your testing today And that's it! By integrating fire-and-forget commands into your command-line workflow, you save a lot of time and resources compared to running multiple emulators simultaneously. Now is the time to start experimenting. If you haven't used these console shortcuts before, open up your terminal, fire up your emulator, head over to the documentation, and get started today!Read the original at Android Developers