运行没有 GUI 的 Android 模拟器(无头 Android)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20869067/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 03:36:56  来源:igfitidea点击:

Run Android emulator without GUI (headless Android)

androidandroid-emulatoradbheadless

提问by Android0077

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

如何在没有 GUI(无头 Android)的情况下运行模拟器?

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

我的要求是在模拟器上运行无头Android。如果我使用它是否正确ro.config.headless 1?或禁用合子

回答by marius bardan

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

Android Emulator 28.1.8 现在支持在无头模式 ( emulator-headless)下运行模拟器:https: //androidstudio.googleblog.com/2019/02/emulator-2818-canary.html

回答by Onik

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

实现这一目标的方法之一是zygote在模拟器运行时停止服务。当停止zygote进程(又名app_process)时,所有zygote在系统启动时分叉的系统服务都会关闭。只有少数本地系统服务会运行。模拟器的显示屏应显示启动徽标(或动画)。

The steps for stopping zygoteare as follows:

停止步骤zygote如下:

  • adb shell
  • su(most of emulator images have /system/xbin/su)
  • stop zygote
  • adb shell
  • su大多数模拟器图像都有/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.

之后,您可以探索使用service list. Android 运行时的关键服务将被停止,例如

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

To start zygoteexecute:

开始zygote执行:

  • start zygote
  • start zygote

Note: with the @CommonsWare's solution you are still going to have zygoteand most of the Androidsystem services running.

注意:使用@CommonsWare 的解决方案,您仍然可以运行zygote大多数Android系统服务。