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

Sam*_*Sam 24 ubuntu android qemu emulation android-virtual-device

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

我使用的是Linux Ubuntu 10.04版本(64位),Android SDK版本是2.3.

我使用它的快照启动了模拟器.现在我关心的是优雅地关闭正在运行的Emulator实例.我已经尝试使用kill -9(模拟器运行的进程ID)关闭模拟器,但下次它没有启动,因为它的快照已损坏.请帮我避免强行关闭模拟器.

知道怎么解决吗?

Die*_*ano 56

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

正确的命令是

 $ adb emu kill
Run Code Online (Sandbox Code Playgroud)

或者我最好最近的一些adb变化之前说这是正确的命令.似乎有人忘了添加身份验证.

最近(截至2016年6月)最新adb版本是

$ adb version
Android Debug Bridge version 1.0.36
Revision 0a04cdc4a62f-android
Run Code Online (Sandbox Code Playgroud)

当你尝试

$ adb emu kill
Run Code Online (Sandbox Code Playgroud)

没有任何反应,这就是原因

...
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 +++
Run Code Online (Sandbox Code Playgroud)

那我们需要另一个解决方案

如果上一个命令不起作用(如某些用户报告的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
Run Code Online (Sandbox Code Playgroud)

然后,您只需kill在命令提示符下输入即可

kill
OK: killing emulator, bye bye
Connection closed by foreign host.
Run Code Online (Sandbox Code Playgroud)

并且模拟器将退出.

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

这个要点提供了一个使用expect的自动化解决方案,而不是每次都必须切断和通过身份验证令牌.

希望你觉得它有用.

  • 这可以在Linux上找到,但在Windows 7上不起作用.有一个错误:http://code.google.com/p/android/issues/detail?id = 21021 (4认同)