$ adb --help
...
-s SERIAL use device with given serial (overrides $ANDROID_SERIAL)
...
$ adb devices List of devices attached emulator-5554 device 7f1c864e device
...
$ adb shell -s 7f1c864e error: more than one device and emulator
?
$ adb --help
...
-s SERIAL use device with given serial (overrides $ANDROID_SERIAL)
...
$ adb devices List of devices attached emulator-5554 device 7f1c864e device
...
$ adb shell -s 7f1c864e error: more than one device and emulator
?
Another alternative would be to set environment variable ANDROID_SERIAL to the relevant serial, here assuming you are using Windows:
Then you can use
adb.exe shell
without any issues.adb -d shell
(oradb -e shell
if you're connecting to an emulator).This command will help you in most of the cases, if you are too lazy to type the full ID.
From http://developer.android.com/tools/help/adb.html#commandsummary:
I found this question after seeing the 'more than one device' error, with 2 offline phones showing:
If you only have one device connected, run the following commands to get rid of the offline connections:
Shouldn't you enter :
?
http://developer.android.com/tools/help/adb.html#directingcommands
Create a Bash (tools.sh) to select a serial from devices (or emulator):
Then in another option can use
adb -s
(global option -s use device with given serial number that overrides $ANDROID_SERIAL):I tested this code on MacOS terminal, but I think it can be used on windows across Git Bash Terminal.
Also remember configure environmental variables and Android SDK paths on
.bash_profile
file:User
@janot
has already mentioned this above, but this took me some time to filter the best solution.There are two Broad use cases:
1) 2 hardware are connected, first is emulator and other is a Device.
Solution :
adb -e shell....whatever-command
for emulator andadb -d shell....whatever-command
for device.2) n number of devices are connected (all emulators or Phones/Tablets) via USB/ADB-WiFi:
Solution: Step1) run
adb devices
THis will give you list of devices currently connected (via USB or ADBoverWiFI)Step2) now run
adb -s <device-id/IP-address> shell....whatever-command
no matter how many devices you have.Example
to clear app data on a device connected on wifi ADB I would execute:
adb -s 172.16.34.89:5555 shell pm clear com.package-id
to clear app data connected on my usb connected device I would execute:
adb -s 5210d21be2a5643d shell pm clear com.package-id