When using the versatile Android Debug Bridge (adb) tool to issue commands, if there’s only one device or emulator attached then that’s fine as the commands will be executed on exactly that. But if there’s more than one instance then we’ll get an error on the terminal saying
error: more than one device and emulator.
In such cases, we’ll need to direct our commands to a specific device doing which is pretty simple. First we should check out all the devices attached:
$ adb devices List of devices attached 017296d5904c device 192.168.56.101:5555 device
The dump generated basically consists of two pieces of data in every line. The first bit (
017296d5904c for example) is the serial number which is a unique identifier for each device whereas the second portion is the connection state of the instance whose value is
device in this case which means that the instance is connected to the adb server. Other values for connection state can be
offline (not connected to adb or not responding) or
no device (no emulator/device connected).
Now in order to direct an adb command to a particular device all we need to do is use the
-s option to specify the serial number of the device.
# my android device $ adb -s 017296d5904c shell pm list packages # my android emulator $ adb -s 192.168.56.101:5555 shell pm list packages
Now if there’s only one attached USB device and/or only one running emulator instance then we don’t need the serial number. Instead we can just use the
-e options respectively.
# my android device $ adb -d shell pm list packages # my android emulator $ adb -e shell pm list packages
Hope that helps!