$ 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
当前回答
为了方便起见,我们可以创建运行配置,设置ANDROID_SERIAL:
adb_wifi.bat可能看起来很像(只有位置参数%1%和“$1”可能不同):
adb tcpip 5555
adb connect %1%:5555
改进之处在于,adb将接收当前的ANDROID_SERIAL。 在shell脚本也ANDROID_SERIAL=xyz adb shell应该工作。
这种说法不一定是错误的:
-s SERIAL use device with given serial (overrides $ANDROID_SERIAL)
但是也可以在运行adb命令之前更改ANDROID_SERIAL。
我们甚至可以设置eg。ANDROID_SERIAL=192.168.2.60:5555定义adb的目标IP。 这也允许运行adb shell,命令被作为“脚本参数”传递。
其他回答
对于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
为了方便起见,我们可以创建运行配置,设置ANDROID_SERIAL:
adb_wifi.bat可能看起来很像(只有位置参数%1%和“$1”可能不同):
adb tcpip 5555
adb connect %1%:5555
改进之处在于,adb将接收当前的ANDROID_SERIAL。 在shell脚本也ANDROID_SERIAL=xyz adb shell应该工作。
这种说法不一定是错误的:
-s SERIAL use device with given serial (overrides $ANDROID_SERIAL)
但是也可以在运行adb命令之前更改ANDROID_SERIAL。
我们甚至可以设置eg。ANDROID_SERIAL=192.168.2.60:5555定义adb的目标IP。 这也允许运行adb shell,命令被作为“脚本参数”传递。
另一种方法是将环境变量ANDROID_SERIAL设置为相关的串行,这里假设你使用的是Windows:
set ANDROID_SERIAL=7f1c864e
echo %ANDROID_SERIAL%
"7f1c864e"
然后你可以使用adb.exe shell没有任何问题。
Adb -d shell(或Adb -e shell)。
如果您懒得输入完整的ID,这个命令在大多数情况下都有帮助。
从http://developer.android.com/tools/help/adb.html # commandsummary:
-d -将adb命令直接到唯一连接的USB设备。当连接多个USB设备时返回错误。 -e -将adb命令直接指向唯一正在运行的模拟器。当多个模拟器正在运行时返回一个错误。
在命令前使用-s选项指定设备,例如:
adb -s 7f1c864e shell
对于多个模拟器,使用进程的IP和端口作为id,例如:
adb -s 192.168.232.2:5555 <command>
参见如何获取Android模拟器的IP地址? 但如果只有一个模拟器,请尝试: Adb -e <命令>
参见http://developer.android.com/tools/help/adb.html#directingcommands