30

How can I run emulator without GUI (headless Android)?

My requirement is to run the headless Android on the emulator. Is it correct if I use ro.config.headless 1? Or disable zygote?

Onik
  • 19,396
  • 14
  • 68
  • 91
Android0077
  • 401
  • 1
  • 6
  • 12
  • My requirement is to run the headless Android on the emulator. Maybe use ro.config.headless 1 ? or disable zygote? Thanks – Android0077 Jan 01 '14 at 13:31
  • Possible duplicate: https://stackoverflow.com/questions/44900957/android-emulator-in-jenkins/47745530 – Martin Zeitler Sep 09 '18 at 10:12
  • @Onik it relates to `Jenkins`, while this is a real-world application for it... here the `user-interface` content tag appears misleading, because the `headless` rules that out. – Martin Zeitler Sep 09 '18 at 10:15

4 Answers4

12

As of 29.2.11, you need to use the -no-window option instead of the emulator-headless binary:

The binary emulator-headless is now retired. Headless builds of the engine are now launched via emulator -no-window, thus unifying the previously separate (but similar) paths.

https://androidstudio.googleblog.com/2019/12/emulator-29211-and-amd-hypervisor-12-to.html

Heath Borders
  • 30,998
  • 16
  • 147
  • 256
8

Android Emulator 28.1.8 now supports running the emulator in headless mode (emulator-headless): https://androidstudio.googleblog.com/2019/02/emulator-2818-canary.html

marius bardan
  • 4,962
  • 4
  • 29
  • 32
2

One of the options to achieve that is to stop zygote service when an emulator running. When stopping the zygote process (aka app_process) all of the system services, that were forked from zygote at system boot, shuts down. Only a few native system services will be running. The emulator's display should show the startup logo (or animation).

The steps for stopping zygote are as follows:

  • adb shell
  • su (most of emulator images have /system/xbin/su)
  • stop zygote

After that you can explore how less services are running with service list. Critical for Android Runtime services will be stopped, e.g.

activity: [] // ActivityManager
package: [] // PackageManager
display: [] // DisplayManager
...

To start zygote execute:

  • start zygote

Note: with the @CommonsWare's solution you are still going to have zygote and most of the Android system services running.

Onik
  • 19,396
  • 14
  • 68
  • 91
0

I was facing an issue with the emulator not running after building AOSP on my ssh server ubuntu 18.4.

emulator: WARNING: system partition size adjusted to match image file (2562 MB > 800 MB) QXcbConnection: Could not connect to display Aborted (core dumped)

I used emulator -no-window and I found the emulator process started. now I can use ADB to verify AOSP changes

Narendra
  • 21
  • 4