Android gets an emulator with a device name, or vice versa

Currently, when I run adb devices , it gives me a list of devices that look something like this:

 emulator-5554 device emulator-5556 device 

My goal is to find a command that I can run in a shell that takes a device name as a parameter, for example. Nexus7 and returns the corresponding serial number of the device, for example. emulator-5554 . If this is not possible, I want to have a function that takes emulator-5554 as a parameter and returns Nexus7 (the opposite direction of the previous function), after which I will Nexus7 over all devices in adb devices and find out which one corresponds to Nexus7 .

UPDATE

I found a workaround that should have indicated the port number when running avd, and then I know which emulator maps to which avd name, but ideally I would still like to know the answer here.

+4
source share
2 answers

This is possible using telnet for the emulator. Unfortunately, this is not one command, but in general it can be automated using the shell. Here is the basic idea:

  • Find the emulator port number (5554):

     $ adb devices List of devices attached emulator-5554 device 
  • Telnet for emulator:

     $ telnet localhost 5554 Trying 127.0.0.1... Connected to localhost. ... OK avd name Nexus7 

Nexus7 is the name avd.

See also this answer to learn how to make telnet in one line: fooobar.com/questions/578829 / ...

+6
source
  • get the PID list for all running emulator processes
  • analyze their cmdlines, collect avd names
  • check TCP ports opened by these processes
  • map open ports to adb devices output
0
source

Source: https://habr.com/ru/post/1490320/


All Articles