MobDev.Emulators (mob_dev v0.5.1)

Copy Markdown View Source

List, start, and stop Android emulators (AVDs) and iOS simulators.

Backs mix mob.emulators. Pure-ish — each function shells out to emulator, adb, or xcrun simctl exactly once and returns a parsed result. UI-shape decisions (formatting, colors, exit codes) live in the Mix task.

Naming

Android calls them "emulators", iOS calls them "simulators". This module uses "emulator" for the cross-platform concept (configured-but-runnable virtual device) and reserves "simulator" for iOS-specific descriptions in the help text. The struct's :platform field disambiguates.

Summary

Functions

Returns all configured Android AVDs, including whether each is currently running. Returns {:error, reason} when the Android SDK isn't reachable.

Returns all installed iOS simulators (across runtimes) marked with their current state. Returns {:error, reason} on a non-macOS host or when xcrun isn't available.

Starts an Android AVD by name. Returns :ok once the emulator process is spawned (it boots in the background; adb wait-for-device is the caller's responsibility if they need to know when it's ready).

Boots an iOS simulator by UDID and brings the Simulator.app to focus. No-op-with-success if the sim is already booted.

Shuts down a running Android emulator by adb serial (e.g. "emulator-5554").

Shuts down a booted iOS simulator by UDID. Pass the literal string "all" to shut down every booted simulator at once (xcrun simctl shutdown all).

Types

t()

@type t() :: %MobDev.Emulators{
  id: String.t(),
  name: String.t(),
  platform: :android | :ios,
  running: boolean(),
  runtime: String.t() | nil,
  serial: String.t() | nil
}

Functions

list_android()

@spec list_android() :: {:ok, [t()]} | {:error, String.t()}

Returns all configured Android AVDs, including whether each is currently running. Returns {:error, reason} when the Android SDK isn't reachable.

list_ios()

@spec list_ios() :: {:ok, [t()]} | {:error, String.t()}

Returns all installed iOS simulators (across runtimes) marked with their current state. Returns {:error, reason} on a non-macOS host or when xcrun isn't available.

start_android(avd_name)

@spec start_android(String.t()) :: :ok | {:error, String.t()}

Starts an Android AVD by name. Returns :ok once the emulator process is spawned (it boots in the background; adb wait-for-device is the caller's responsibility if they need to know when it's ready).

start_ios(udid)

@spec start_ios(String.t()) :: :ok | {:error, String.t()}

Boots an iOS simulator by UDID and brings the Simulator.app to focus. No-op-with-success if the sim is already booted.

stop_android(serial)

@spec stop_android(String.t()) :: :ok | {:error, String.t()}

Shuts down a running Android emulator by adb serial (e.g. "emulator-5554").

stop_ios(udid_or_all)

@spec stop_ios(String.t()) :: :ok | {:error, String.t()}

Shuts down a booted iOS simulator by UDID. Pass the literal string "all" to shut down every booted simulator at once (xcrun simctl shutdown all).