views:

633

answers:

4

If I run several emulators with -no-window option in one machine. The command "adb devices" shows:

List of devices attached
emulator-5554  device
emulator-5556  device
emulator-5558  device
...

However, according to this output, I can't tell the difference between each emulator device at all. I need to know which emulator runs on what AVD, then I can install APKs or send commands to the emulator.

How can I recognize each emulator device or get the serial number of emulator after it runs?

A: 

The same string (e.g., emulator-5554) is show in the title bar of the emulator window.

CommonsWare
Thanks for your response. I must run all emulators with -no-window option. So, there is no window title bar.
papalagi
Please explain how you do Android application development in such a way that requires you to run multiple emulators, each with the -no-window option.
CommonsWare
I try to automatically run test cases of many projects simultaneously on same server. In order not to interfere test results, I think it is better to create an AVD for each project. So I must recognize each emulator to install the correct APK and send right commands by using shell scripts.If there is no better way to get the serial number of an emulator, I will diff the output of "adb devices" command before and after starting an emulator to determine the serial number.
papalagi
First, that's a really cool setup. But, yes, I suspect a diff or something may be your best bet to get the emulator ID. I haven't used -no-window -- I assume it's not dumping the emulator ID out to stdout or something as part of executing the command.
CommonsWare
A: 

"adb get-serialno" command can get correct serial number when only one emulator is running. When there are multiple emulators running, it will return "unknown". Maybe, I should diff the output of "adb device" before and after starting an emulator.

papalagi
+2  A: 

Always start the same AVD on the same ports, don't let emulator decide. Use

$ emulator -ports X,Y @avd_X

then, the serial number will be emulator-X and your avd_X will always be on ports X,Y, so you can run your commands with this serial number, like for example

$ adb -s emualtor-X shell cmd

To kill the emulator run

$ adb -s emulator-X emu kill
dtmilano
Thank you, dtmilano. Your solution works very well.
papalagi
@dtmilano - note the OP has a question about this
Marc Gravell
A: 

@dtmilano:: Ur answer regarding how to use the same port is awesome. However, I tried using the cmd

> adb -s emulator-X kill-server

and many other similar commands. I was really looking at an alternative that will result the avd options without logging into Telnet forever.

KK