google-deepmind/android_env

ML research on Android devices.

AndroidEnv — What It Is

AndroidEnv is a platform (written in Python and Kotlin) for controlling and reading data from Android devices — either virtual emulators or physical phones/tablets. It's designed for three audiences: AI agents that interact with phone UIs, automated testing, and reinforcement-learning (RL) research. Its core promise is low-latency control and telemetry over any Android app, on an unmodified Android OS.

The Three Pieces (v2)

The project splits device interaction from RL task logic into three components:

  1. AndroidDevice — Direct control & telemetry. A task-free handle that connects to a Kotlin server running on the device (over WebSockets). It can stream screenshots, accessibility trees, system logs, and sensor data, and it can inject touch gestures, key events, text, and ADB commands.

  2. AndroidEnv & TaskWrapper — Reinforcement Learning layer. An optional layer on top of AndroidDevice that adds RL semantics: step(), reset(), rewards, and episode terminations. Tasks are defined via custom .textproto files and reward parsers, and it works with dm_env / Gymnasium wrappers.

  3. Playground & MCP Server. A responsive web workbench for live screen interaction, accessibility-tree inspection, and ADB command execution from a browser. Plus a stdio Model Context Protocol (MCP) server (android-env-mcp) that exposes the device to LLM agents.

Key Features

  • Real Android ecosystem: Agents interact with the actual Android OS — same apps, UI frameworks, and system services real users see — on emulators or physical devices.
  • Subscription-based telemetry (DeviceState): Subscribe on demand to:
    • Screenshots (high-speed decoded RGB frame buffers with width, height, raw pixels)
    • Accessibility trees (full window and UI node hierarchies from the on-device AccessibilityService)
    • System & sensor streams: foreground package/activity, logcat, device settings, GPS, audio output, and IMU sensors (accelerometer, gyroscope, magnetometer, barometer, light, proximity)
  • Expressive actions (Action):
    • Touch & multi-touch gestures: normalized (x, y) coordinates in [0.0, 1.0] with TOUCH_DOWN, TOUCH_MOVE, TOUCH_UP across multiple pointer_id fingers (taps, swipes, scrolls, pinches)
    • Hardware keys & native text: inject keycodes (BACK, HOME, ENTER), set text directly on focused UI nodes, or trigger clipboard actions (CUT, COPY, PASTE)
    • Direct ADB execution: run structured or generic AdbRequest commands via device.execute_adb_call()
  • Composable RL layer: Wrap AndroidDevice with AndroidEnv and TaskWrapper for custom tasks, reward parsers, and dm_env/Gymnasium wrappers.

Getting Started (from the README)

  • Install: python3 -m pip install android-env (or clone and build with Bazel)
  • Set up a device: Connect a physical device via USB debugging, or create an Android Virtual Device (AVD) in Android Studio.
  • Direct control: Use AndroidDevice in a Python context manager — subscribe to signals, read state, send actions (e.g., tap center of screen).
  • Playground: android-env-playground --serial=emulator-5554 (after pip install "android-env[playground]")
  • MCP server: android-env-mcp --serial=emulator-5554 (after pip install "android-env[mcp]")
  • RL: pip install "android-env[rl]" and follow the Tasks guide.

Origin

Developed and maintained by Google DeepMind. There's a technical report on arXiv (2105.13231) and an introductory blog post. The README includes a BibTeX citation for research use. Note the disclaimer: this is not an official Google product.

Related

  • Project
  • Project
  • Dispatch
  • Project
  • Project