$ 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
当前回答
用户@janot已经在上面提到了这一点,但是这花了我一些时间来筛选最佳解决方案。
有两个广泛的用例: 1) 2个硬件连接,第一个是模拟器,另一个是设备。 处理步骤:adb -e shell....模拟器和adb -d shell....设备的任何命令。
2) n个设备(所有模拟器或手机/平板电脑)通过USB/ADB-WiFi连接: 解决方案: 这将给你当前连接的设备列表(通过USB或ADBoverWiFI) Step2)现在运行adb -s <device-id/IP-address> shell....whatever-命令 不管你有多少设备。
在连接wifi的设备上清除应用程序数据的示例ADB I将执行: Adb -s 172.16.34.89:5555 shell PM清除com.package-id
清除连接到usb设备上的应用程序数据,我将执行: Adb -s 5210d21be2a5643d shell PM清除com.package-id
其他回答
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 $(android-select-device) shell
1) 02783201431feeee device 3) emulator-5554
2) 3832380FA5F30000 device 4) emulator-5556
Select the device to use, <Q> to quit:
为了避免输入,您可以创建一个别名,其中包括此处解释的设备选择。
用户@janot已经在上面提到了这一点,但是这花了我一些时间来筛选最佳解决方案。
有两个广泛的用例: 1) 2个硬件连接,第一个是模拟器,另一个是设备。 处理步骤:adb -e shell....模拟器和adb -d shell....设备的任何命令。
2) n个设备(所有模拟器或手机/平板电脑)通过USB/ADB-WiFi连接: 解决方案: 这将给你当前连接的设备列表(通过USB或ADBoverWiFI) Step2)现在运行adb -s <device-id/IP-address> shell....whatever-命令 不管你有多少设备。
在连接wifi的设备上清除应用程序数据的示例ADB I将执行: Adb -s 172.16.34.89:5555 shell PM清除com.package-id
清除连接到usb设备上的应用程序数据,我将执行: Adb -s 5210d21be2a5643d shell PM清除com.package-id
在所有连接的设备上运行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+//+命令
你可以使用它来连接你的特定设备:
* 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
也许这能帮到别人