Emulator Module
Emulate Android Virtual Devices (AVDs).
android_device_manager.emulator.EmulatorManager
Manager for starting and stopping Android emulator instances.
Functions
__init__(sdk)
Initialize the EmulatorManager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sdk
|
AndroidSDK
|
The SDK wrapper containing the path to the emulator. |
required |
start_emulator(avd_name, emulator_config=None)
Start an Android emulator for a given AVD.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
avd_name
|
str
|
The name of the AVD to start. |
required |
emulator_config
|
Optional[EmulatorConfiguration]
|
Optional configuration for the emulator. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The port on which the emulator is running. |
Raises:
| Type | Description |
|---|---|
EmulatorPortAllocationError
|
If no free emulator port can be found. |
EmulatorStartError
|
If the emulator fails to start. |
stop_emulator()
Stop the currently running emulator process.
Terminates the emulator process if it is still running. If the process does not stop gracefully within 10 seconds, it is forcibly killed.
__del__()
Cleanup emulator process on destruction.
android_device_manager.emulator.EmulatorConfiguration
dataclass
Configuration options for the Android emulator.
This dataclass encapsulates various parameters that can be passed to the Android emulator at startup. Each field corresponds to a common emulator option.
Attributes:
| Name | Type | Description |
|---|---|---|
no_window |
bool
|
If True, launch the emulator without a window (headless). |
no_audio |
bool
|
If True, disable audio in the emulator. |
gpu |
str
|
GPU emulation mode (default "auto", e.g., "host", "swiftshader_indirect"). |
memory |
Optional[int]
|
Memory (in MB) to allocate for the emulator. |
cores |
Optional[int]
|
Number of CPU cores for the emulator. |
wipe_data |
bool
|
If True, wipe user data when starting the emulator. |
no_snapshot |
bool
|
If True, disable snapshots. |
cold_boot |
bool
|
If True, force cold boot (do not load quick-boot snapshot). |
netdelay |
str
|
Network delay profile (e.g., "none", "gsm", "edge", "umts"). |
netspeed |
str
|
Network speed profile (e.g., "full", "gsm", "edge"). |
verbose |
bool
|
If True, enable verbose output. |
Functions
to_args()
Convert the configuration to a list of command-line arguments for the emulator.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: The list of emulator CLI arguments corresponding to this configuration. |
android_device_manager.emulator.exceptions
Classes
EmulatorPortAllocationError
Bases: AndroidDeviceManagerError
Exception raised when the emulator fails to allocate a valid port.
This error typically occurs when there are no available ports or when the requested port is already in use.
EmulatorStartError
Bases: AndroidDeviceManagerError
Exception raised when the Android emulator fails to start properly.