连接多个设备时如何使用ADB Shell?失败“错误:多个设备和模拟器”

当有多台设备或模拟器连接时,使用ADB Shell会遇到'错误:多个设备和模拟器'。为了解决这个问题,可以在命令前使用设备序列号选项,如`-s <device_serial>`或`-e`(针对模拟器)。另外,可以设置环境变量ANDROID_SERIAL,或者通过运行特定命令消除离线设备连接。此外,创建一个bash脚本可以方便地在所有连接的设备上执行ADB命令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文翻译自:How to use ADB Shell when Multiple Devices are connected? Fails with “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 

?


#1楼

参考:https://stackoom.com/question/zUMQ/连接多个设备时如何使用ADB-Shell-失败-错误-多个设备和模拟器


#2楼

Use the -s option BEFORE the command to specify the device, for example: 在命令之前使用-s选项指定设备,例如:

adb -s 7f1c864e shell

See also http://developer.android.com/tools/help/adb.html#directingcommands 另请参阅http://developer.android.com/tools/help/adb.html#directingcommands


#3楼

adb -d shell (or adb -e shell if you're connecting to an emulator). adb -d shell (如果要连接到模拟器,则为adb -e shell )。

This command will help you in most of the cases, if you are too lazy to type the full ID. 如果您懒得输入完整ID,此命令将在大多数情况下为您提供帮助。

From http://developer.android.com/tools/help/adb.html#commandsummary : 来自http://developer.android.com/tools/help/adb.html#commandsummary

-d - Direct an adb command to the only attached USB device. -d - 将adb命令指向唯一连接的USB设备。 Returns an error when more than one USB device is attached. 连接多个USB设备时返回错误。

-e - Direct an adb command to the only running emulator. -e - 将adb命令指向唯一正在运行的模拟器。 Returns an error when more than one emulator is running. 运行多个仿真器时返回错误。


#4楼

Another alternative would be to set environment variable ANDROID_SERIAL to the relevant serial, here assuming you are using Windows: 另一种方法是将环境变量ANDROID_SERIAL设置为相关的序列,这里假设您使用的是Windows:

set ANDROID_SERIAL="7f1c864e"
echo %ANDROID_SERIAL%
"7f1c864e"

Then you can use adb.exe shell without any issues. 然后你就可以使用adb.exe shell而不会出现任何问题。


#5楼

I found this question after seeing the 'more than one device' error, with 2 offline phones showing: 我看到“多个设备”错误后发现了这个问题,其中有2个离线手机显示:

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

If you only have one device connected, run the following commands to get rid of the offline connections: 如果只连接了一个设备,请运行以下命令以消除脱机连接:

adb kill-server
adb devices

#6楼

Running adb commands on all connected devices 在所有连接的设备上运行adb命令

Create a bash (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

done use it with 完成使用它

adb+ //+ command adb + // +命令

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值