如何通过命令行关闭Android模拟器

发布于 2024-11-05 15:36:21 字数 241 浏览 1 评论 0 原文

我无法从命令提示符正常停止模拟器。

我使用的是 Linux Ubuntu v10.04(64 位)和 Android v2.3(API 9 - Gingerbread)。

我使用其快照启动了模拟器。现在我关心的是优雅地关闭正在运行的模拟器实例。我尝试过使用 kill -9 (模拟器运行的进程 ID)来关闭模拟器,但下次它不会启动,因为它的快照已损坏。请帮助我避免强制关闭模拟器。

知道如何修复它吗?

I am unable to stop the emulator from command prompt gracefully.

I am using Linux Ubuntu v10.04 (64-bit) and Android v2.3 (API 9 - Gingerbread).

I started emulator using its snapshot. Now my concern is to shut down the running instance of Emulator gracefully. I have tried with kill -9 (process Id for emulator running) which shuts down the emulator but next time it does not start as its snapshot got corrupted. Please help me to avoid forceful shutdown of the an emulator.

Any idea how to fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

终遇你 2024-11-12 15:36:21

请不要乱用kill -9,这是一个非常不好的习惯。

正确的命令是

 $ adb emu kill

或者我最好说它是正确的命令,直到最近的一些 adb 更改。似乎有人忘记添加身份验证。

在最新的(截至 2016 年 6 月)最新的 adb 版本中

$ adb version
Android Debug Bridge version 1.0.36
Revision 0a04cdc4a62f-android

,当您尝试时

$ adb emu kill

没有任何反应,这就是为什么

...
connect(3, {sa_family=AF_INET, sin_port=htons(5554), 
sin_addr=inet_addr("127.0.0.1")}, 16) = 0
write(3, "kill\nquit\n", 10)            = 10
read(3, "\377\373\1", 8192)             = 3
read(3, "\377\373\3\377\373\0\377\375\0", 8192) = 9
read(3, "Android Console: Authentication required\r\nAndroid Console: type 'auth <auth_token>' to authenticate\r\nAndroid Console: you can find your <auth_token> in \r\n'/home/diego/.emulator_console_auth_token'\r\nOK\r\n", 8192) = 202
read(3, "k\33[K", 8192)                 = 4
read(3, "\33[Dki\33[K", 8192)           = 8
read(3, "\33[D\33[Dkil\33[K\33[D\33[D\33[Dkill\33[K", 8192) = 28
read(3, "\r\nKO: unknown command, try 'help'\r\n", 8192) = 35
read(3, "q\33[K\33[Dqu\33[K", 8192)     = 12
read(3, "\33[D\33[Dqui\33[K\33[D\33[D\33[Dquit\33[K", 8192) = 28
read(3, "\r\n", 8192)                   = 2
read(3, "", 8192)                       = 0
close(3)                                = 0
exit_group(0)                           = ?
+++ exited with 0 +++

然后我们需要另一个解决方案。

如果上一个命令不起作用(正如一些 Windows 用户报告的那样),您可以尝试(在下一个命令中 5554 是模拟器使用的端口)。

将令牌文件 (~/.emulator_console_auth_token) 的内容复制到剪贴板,以便您可以在 telnet 会话期间粘贴它:

$ telnet localhost 5554

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Android Console: Authentication required
Android Console: type 'auth <auth_token>' to authenticate
Android Console: you can find your <auth_token> in 
'/home/user/.emulator_console_auth_token'
OK
auth <YOUR_TOKEN_HERE>
Android Console: type 'help' for a list of commands
OK
Android console command help:

    help|h|?         print a list of commands
    crash            crash the emulator instance
    kill             kill the emulator instance
    quit|exit        quit control session
    redir            manage port redirections
    power            power related commands
    event            simulate hardware events
    avd              control virtual device execution
    finger           manage emulator fingerprint
    geo              Geo-location commands
    sms              SMS related commands
    cdma             CDMA related commands
    gsm              GSM related commands
    rotate           rotate the screen by 90 degrees

try 'help <command>' for command-specific help
OK

然后,您只需在命令中输入 kill提示

kill
OK: killing emulator, bye bye
Connection closed by foreign host.

,模拟器将退出。

但是等等,应该有更好的方法。事实上是有的!

这个要点使用expect 而不必每次都剪切并传递身份验证令牌。

希望您觉得它有用。

Please don't use kill -9 indiscriminately, it's a very bad habit.

The correct command is

 $ adb emu kill

Or I should better say it was the correct command until some recent adb changes. It seems somebody forgot to add the authentication to it.

In the latest (as of June 2016) the latest adb version is

$ adb version
Android Debug Bridge version 1.0.36
Revision 0a04cdc4a62f-android

and when you try

$ adb emu kill

nothing happens, and this is why

...
connect(3, {sa_family=AF_INET, sin_port=htons(5554), 
sin_addr=inet_addr("127.0.0.1")}, 16) = 0
write(3, "kill\nquit\n", 10)            = 10
read(3, "\377\373\1", 8192)             = 3
read(3, "\377\373\3\377\373\0\377\375\0", 8192) = 9
read(3, "Android Console: Authentication required\r\nAndroid Console: type 'auth <auth_token>' to authenticate\r\nAndroid Console: you can find your <auth_token> in \r\n'/home/diego/.emulator_console_auth_token'\r\nOK\r\n", 8192) = 202
read(3, "k\33[K", 8192)                 = 4
read(3, "\33[Dki\33[K", 8192)           = 8
read(3, "\33[D\33[Dkil\33[K\33[D\33[D\33[Dkill\33[K", 8192) = 28
read(3, "\r\nKO: unknown command, try 'help'\r\n", 8192) = 35
read(3, "q\33[K\33[Dqu\33[K", 8192)     = 12
read(3, "\33[D\33[Dqui\33[K\33[D\33[D\33[Dquit\33[K", 8192) = 28
read(3, "\r\n", 8192)                   = 2
read(3, "", 8192)                       = 0
close(3)                                = 0
exit_group(0)                           = ?
+++ exited with 0 +++

Then we need another solution.

If the previous command does not work (as some users reported for Windows) you can try (in the next command 5554 is the port used by the emulator).

Copy the content of the token file (~/.emulator_console_auth_token) to the clipboard so you can paste it during your telnet session:

$ telnet localhost 5554

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Android Console: Authentication required
Android Console: type 'auth <auth_token>' to authenticate
Android Console: you can find your <auth_token> in 
'/home/user/.emulator_console_auth_token'
OK
auth <YOUR_TOKEN_HERE>
Android Console: type 'help' for a list of commands
OK
Android console command help:

    help|h|?         print a list of commands
    crash            crash the emulator instance
    kill             kill the emulator instance
    quit|exit        quit control session
    redir            manage port redirections
    power            power related commands
    event            simulate hardware events
    avd              control virtual device execution
    finger           manage emulator fingerprint
    geo              Geo-location commands
    sms              SMS related commands
    cdma             CDMA related commands
    gsm              GSM related commands
    rotate           rotate the screen by 90 degrees

try 'help <command>' for command-specific help
OK

Then, you can just enter kill at the command prompt

kill
OK: killing emulator, bye bye
Connection closed by foreign host.

and the emulator will exit.

But wait, there should be a better way. And in fact there is!

This gist provides an automated solution using expect instead of having to cut and past the authentication token every time.

Hope you find it useful.

转身以后 2024-11-12 15:36:21

我在 ubuntu 中遇到问题,模拟器会不断打开新进程。我永远无法关闭模拟器并且它没有响应。

我使用了htop

htop中的步骤:

  1. F4来过滤。
  2. 过滤“avd”。
  3. F5 为树。
  4. 找到并单击父进程。
  5. F9 调出杀死菜单。
  6. 选择信号 9 并输入。

I had issues in ubuntu where the emulator would continuously open new processes. I could never close the emulator and it was unresponsive.

I used htop

Steps in htop:

  1. F4 to filter.
  2. Filter for 'avd'.
  3. F5 for tree.
  4. Find and click on parent process.
  5. F9 to raise kill menu.
  6. Select signal 9 and enter.
游魂 2024-11-12 15:36:21

在 Ubuntu 16-04 上,使用 ADB 版本 1.0.32,我在 Docker 容器中运行 Android 4.4 (API 19) 模拟器。控制台暴露的端口为 30004,ADB 暴露的端口为 30005。

我可以通过执行 adb connect 0.0.0.0:30005 连接到它。

不过,要杀死模拟器,我必须使用adb -s emulator-30004 emu Kill,使用0.0.0.0:30005给我错误:未检测到模拟器< /代码>。

On Ubuntu 16-04, using ADB version 1.0.32, I'm running the emulator for Android 4.4 (API 19) in a docker container. The exposed ports are 30004 for the console and 30005 for ADB.

I can connect to it by doing adb connect 0.0.0.0:30005.

To kill the emulator though, I have to use adb -s emulator-30004 emu kill, using 0.0.0.0:30005 gives me error: no emulator detected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文