This question is identical to How to shut down Android emulator via command line.
此问题与如何通过命令行关闭Android模拟器相同。
However, after attempting the suggested solution from the first answer adb emu kill
has not proven successful for me.
但是,在尝试从第一个答案adb emu kill建议的解决方案后,我没有被证明是成功的。
I am automating unit tests for an android application. My bash script runs on a headless machine. It creates an android device using android create avd
and executes emulator
with the -no-window
attribute. It then compiles the test project, connects to the emulator using adb
, installs the project and executes my tests. This all works fine.
我正在为Android应用程序自动化单元测试。我的bash脚本在无头机器上运行。它使用android create avd创建一个android设备,并使用-no-window属性执行模拟器。然后它编译测试项目,使用adb连接到模拟器,安装项目并执行我的测试。一切正常。
Now I need to terminate the emulator process, and just like the referenced post, I am only able to do this using kill -9
.
现在我需要终止模拟器进程,就像引用的帖子一样,我只能使用kill -9来做到这一点。
The Google tutorial Managing AVDs from the Command Line only mentions how to stop emulators within a GUI environment.
从命令行管理AVD的Google教程仅提到了如何在GUI环境中停止模拟器。
Any help is appreciated.
任何帮助表示赞赏。
9 个解决方案
#1
89
Maybe try using adb kill-server
it should work for you?
也许尝试使用adb kill-server它应该适合你?
or
要么
adb -s emulator-5554 emu kill
, where emulator-5554
is the emulator name.
adb -s emulator-5554 emu kill,其中emulator-5554是模拟器名称。
Also read : http://devmaze.wordpress.com/2011/12/12/starting-and-stopping-android-emulators/
另请阅读:http://devmaze.wordpress.com/2011/12/12/starting-and-stopping-android-emulators/
For Ubuntu users I found a good command to stop all running emulators (Thanks to @uwe)
对于Ubuntu用户,我发现了一个很好的命令来停止所有正在运行的模拟器(感谢@uwe)
adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done
#2
23
To stop all running emulators we use this command:
要停止所有正在运行的模拟器,我们使用此命令:
adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done
#3
7
The other answer didn't work for me (on Windows 7). But this worked:
另一个答案对我不起作用(在Windows 7上)。但这有效:
telnet localhost 5554
kill
#4
4
Why not just do
为什么不这样做
adb reboot bootloader
#5
1
adb kill-server will kill all emulators and restart the server clean.
adb kill-server将终止所有模拟器并重新启动服务器清理。
#6
1
None of the solutions worked for me. I had to go the telnet way including authentication:
这些解决方案都不适合我。我必须采用telnet方式,包括身份验证:
AUTH=$(cat "$HOME/.emulator_console_auth_token")
expect << EOF
spawn telnet localhost 5554
expect "OK"
send "auth $AUTH\r"
expect "OK"
send "kill\r"
expect "OK"
send "exit\r"
EOF
The full script can be obtained with a free license from https://github.com/kullo/android-emulator-tools
完整的脚本可以通过https://github.com/kullo/android-emulator-tools获得免费许可证
Update: looks like this still does not reliably close the console and ADB ports (e.g. 5554,5555)
更新:看起来仍然无法可靠地关闭控制台和ADB端口(例如5554,5555)
#7
1
I use this one-liner, broken into several lines for readability:
我使用这个单行,分为几行以便于阅读:
adb devices |
perl -nle 'print $1 if /emulator-(\d+).device$/' |
xargs -t -l1 -i bash -c "
( echo auth $(cat $HOME/.emulator_console_auth_token) ;
echo kill ;
yes ) |
telnet localhost {}"
#8
0
List of devices attached emulator-5584 host emulator-5580 host emulator-5576 host emulator-5572 host emulator-5568 host emulator-5564 host emulator-5560 host
设备列表连接模拟器-5584主机模拟器-5580主机模拟器-5576主机模拟器-5572主机模拟器-5568主机模拟器-5564主机模拟器-5560主机
C:\Users\Administrator>adb -s emulator-5584 emu kill error: could not connect to TCP port 5584: cannot connect to 127.0.0.1:5584: No connection could be made because the target machine actively refused it. (10061)
C:\ Users \ Administrator> adb -s emulator-5584 emu kill error:无法连接到TCP端口5584:无法连接到127.0.0.1:5584:无法建立连接,因为目标计算机主动拒绝它。 (10061)
NOTE: gui of emulator is not running but still it's showing
注意:模拟器的gui没有运行但仍在显示
SOLUTION:
解:
adb kill-server
start emulator using:
启动模拟器使用:
emulator.exe -netdelay none -netspeed full -avd Nexus_5X_API_19
I hope this will help you!
我希望这能帮到您!
#9
0
To automate this, you can use any script or app that can send a string to a socket. I personally like nc (netcat) under cygwin. As I said before, I use it like this:
要自动执行此操作,您可以使用任何可以将字符串发送到套接字的脚本或应用程序。我个人喜欢cygwin下的nc(netcat)。正如我之前所说,我这样使用它:
$ echo kill | nc -w 2 localhost 5554
(that means to send "kill" string to the port 5554 on localhost, and terminate netcat after 2 seconds.)
(这意味着将“kill”字符串发送到localhost上的端口5554,并在2秒后终止netcat。)
#1
89
Maybe try using adb kill-server
it should work for you?
也许尝试使用adb kill-server它应该适合你?
or
要么
adb -s emulator-5554 emu kill
, where emulator-5554
is the emulator name.
adb -s emulator-5554 emu kill,其中emulator-5554是模拟器名称。
Also read : http://devmaze.wordpress.com/2011/12/12/starting-and-stopping-android-emulators/
另请阅读:http://devmaze.wordpress.com/2011/12/12/starting-and-stopping-android-emulators/
For Ubuntu users I found a good command to stop all running emulators (Thanks to @uwe)
对于Ubuntu用户,我发现了一个很好的命令来停止所有正在运行的模拟器(感谢@uwe)
adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done
#2
23
To stop all running emulators we use this command:
要停止所有正在运行的模拟器,我们使用此命令:
adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done
#3
7
The other answer didn't work for me (on Windows 7). But this worked:
另一个答案对我不起作用(在Windows 7上)。但这有效:
telnet localhost 5554
kill
#4
4
Why not just do
为什么不这样做
adb reboot bootloader
#5
1
adb kill-server will kill all emulators and restart the server clean.
adb kill-server将终止所有模拟器并重新启动服务器清理。
#6
1
None of the solutions worked for me. I had to go the telnet way including authentication:
这些解决方案都不适合我。我必须采用telnet方式,包括身份验证:
AUTH=$(cat "$HOME/.emulator_console_auth_token")
expect << EOF
spawn telnet localhost 5554
expect "OK"
send "auth $AUTH\r"
expect "OK"
send "kill\r"
expect "OK"
send "exit\r"
EOF
The full script can be obtained with a free license from https://github.com/kullo/android-emulator-tools
完整的脚本可以通过https://github.com/kullo/android-emulator-tools获得免费许可证
Update: looks like this still does not reliably close the console and ADB ports (e.g. 5554,5555)
更新:看起来仍然无法可靠地关闭控制台和ADB端口(例如5554,5555)
#7
1
I use this one-liner, broken into several lines for readability:
我使用这个单行,分为几行以便于阅读:
adb devices |
perl -nle 'print $1 if /emulator-(\d+).device$/' |
xargs -t -l1 -i bash -c "
( echo auth $(cat $HOME/.emulator_console_auth_token) ;
echo kill ;
yes ) |
telnet localhost {}"
#8
0
List of devices attached emulator-5584 host emulator-5580 host emulator-5576 host emulator-5572 host emulator-5568 host emulator-5564 host emulator-5560 host
设备列表连接模拟器-5584主机模拟器-5580主机模拟器-5576主机模拟器-5572主机模拟器-5568主机模拟器-5564主机模拟器-5560主机
C:\Users\Administrator>adb -s emulator-5584 emu kill error: could not connect to TCP port 5584: cannot connect to 127.0.0.1:5584: No connection could be made because the target machine actively refused it. (10061)
C:\ Users \ Administrator> adb -s emulator-5584 emu kill error:无法连接到TCP端口5584:无法连接到127.0.0.1:5584:无法建立连接,因为目标计算机主动拒绝它。 (10061)
NOTE: gui of emulator is not running but still it's showing
注意:模拟器的gui没有运行但仍在显示
SOLUTION:
解:
adb kill-server
start emulator using:
启动模拟器使用:
emulator.exe -netdelay none -netspeed full -avd Nexus_5X_API_19
I hope this will help you!
我希望这能帮到您!
#9
0
To automate this, you can use any script or app that can send a string to a socket. I personally like nc (netcat) under cygwin. As I said before, I use it like this:
要自动执行此操作,您可以使用任何可以将字符串发送到套接字的脚本或应用程序。我个人喜欢cygwin下的nc(netcat)。正如我之前所说,我这样使用它:
$ echo kill | nc -w 2 localhost 5554
(that means to send "kill" string to the port 5554 on localhost, and terminate netcat after 2 seconds.)
(这意味着将“kill”字符串发送到localhost上的端口5554,并在2秒后终止netcat。)