$ 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

当前回答

对于Windows,这里有一个简单的例子,告诉你如何在多个设备上安装一个文件

FOR /F "skip=1"  %x IN ('adb devices') DO start adb -s %x install -r myandroidapp.apk

如果您计划在批处理文件中包含此文件,请将%x替换为%%x,如下所示

FOR /F "skip=1"  %%x IN ('adb devices') DO start adb -s %%x install -r myandroidapp.apk

其他回答

在所有连接的设备上运行adb命令

创建一个bash (adb+)

adb devices | while read line
do
if [ ! "$line" = "" ] && [ `echo $line | awk '{print $2}'` = "device" ]
then
    device=`echo $line | awk '{print $1}'`
    echo "$device $@ ..."
    adb -s $device $@
fi

完成 使用它

adb+//+命令

https://developer.android.com/studio/command-line/adb#directingcommands

对我的测试有效的方法:

Ubuntu bash终端:

$ adb devices
List of devices attached 
646269f0    device
8a928c2 device
$ export ANDROID_SERIAL=646269f0
$ echo $ANDROID_SERIAL
646269f0
$ adb reboot bootloader

Windows命令提示符:

$ adb devices
List of devices attached 
646269f0    device
8a928c2 device
$ set ANDROID_SERIAL=646269f0
$ echo $ANDROID_SERIAL$
646269f0
$ adb reboot bootloader

这使您可以使用正常的命令和脚本,就好像只有ANDROID_SERIAL设备附加。

或者,您可以每次都提到设备序列号。

$ adb -s 646269f0 shell

你可以使用它来连接你的特定设备:

   * adb devices
  --------------
    List of devices attached
    9f91cc67    offline
    emulator-5558   device

我想连接到第一个设备“9f91cc67”

* adb -s 9f91cc67 tcpip 8080
---------------------------
restarting in TCP mode port: 8080

then

* adb -s 9f91cc67 connect 192.168.1.44:8080
----------------------------------------
connected to 192.168.1.44:8080

也许这能帮到别人

在看到“不止一个设备”错误后,我发现了这个问题,2个离线电话显示:

C:\Program Files (x86)\Android\android-sdk\android-tools>adb devices
List of devices attached
SH436WM01785    offline
SH436WM01785    offline
SH436WM01785    sideload

如果您只连接了一台设备,请执行以下命令清除离线连接:

adb kill-server
adb devices

在任何特定设备上运行shell的最佳方式是使用:

adb -s << emulator UDID >> shell

For Example:
adb -s emulator-5554 shell