用命令禁用Android某个进程,如何通过命令行关闭Android仿真器

问题描述

我无法从命令提示符处优雅地停止模拟器。

我正在使用Linux Ubuntu 10.04版本(64位),Android SDK版本是2.3。

我使用其快照启动了模拟器。现在,我关心的是正常关闭正在运行的Emulator实例。我曾尝试使用kill -9(正在运行模拟器的进程ID)关闭模拟器,但下一次由于快照损坏而无法启动。请帮助我避免强行关闭仿真器。

知道如何解决吗?

最佳回答

请不要随意使用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 ' to authenticate\r\nAndroid Console: you can find your 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 ' to authenticate

Android Console: you can find your in

'/home/user/.emulator_console_auth_token'

OK

auth

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 ' for command-specific help

OK

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

kill

OK: killing emulator, bye bye

Connection closed by foreign host.

模拟器将退出。

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

此gist提供了使用expect的自动化解决方案,而不必每次都剪切和粘贴身份验证令牌。

希望你觉得它有用。

参考资料

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值