How To Shut Down Android Emulator Via Command Line
Solution 1:
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 commandhelp:
help|h|? print a list of commands
crash crash the emulator instance
killkill 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, byebye
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.
Solution 2:
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:
- F4 to filter.
- Filter for 'avd'.
- F5 for tree.
- Find and click on parent process.
- F9 to raise kill menu.
- Select signal 9 and enter.
Solution 3:
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
.
Post a Comment for "How To Shut Down Android Emulator Via Command Line"