$ 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
在命令之前使用-s
选项来指定设备,例如:
adb -s 7f1c864e shell
对于多个模拟器,使用进程的 IP 和端口作为标识,例如:
adb -s 192.168.232.2:5555 <command>
但如果只有一个模拟器,请尝试以下方法:
adb -e <command>
也请参阅 http://developer.android.com/tools/help/adb.html#directingcommands。adb -d shell
(或者 adb -e shell
)。
这个命令在大多数情况下都能帮到您,如果您懒得输入完整的ID。
参考http://developer.android.com/tools/help/adb.html#commandsummary:
-d
- 将adb指令直接传送到唯一的已连接USB设备。当连接了多个USB设备时会返回一个错误。
-e
- 将adb指令直接传送到唯一的正在运行的模拟器。当有多个模拟器在运行时会返回一个错误。
-d
表示 **"设备"**,而 -e
则表示 **"模拟器"**。如果你已经明白了这个规律,那么就可以为自己鼓掌了 ;) - Joshua Pinter另一种选择是将环境变量ANDROID_SERIAL设置为相关串行号,这里假设你正在使用Windows:
set ANDROID_SERIAL=7f1c864e
echo %ANDROID_SERIAL%
"7f1c864e"
然后您可以使用 adb.exe shell
而不会遇到任何问题。
set ANDROID_SERIAL=7f1c864e
,即不需要引号。 - Bjonnfeskexport ANDROID_SERIAL=7f1c864e
。 - nivekmai$env:ANDROID_SERIAL="7f1c864e"
。 - tteng little安装APK到您的模拟器之一:
首先获取设备列表:
-> adb devices
List of devices attached
25sdfsfb3801745eg device
emulator-0954 device
然后使用-s
标志在模拟器上安装apk:
-> adb -s "25sdfsfb3801745eg" install "C:\Users\joel.joel\Downloads\release.apk"
Performing Streamed Install
Success
顺便提醒一下,这里的顺序很重要,所以-s <id>
命令必须在install
命令之前使用,否则它不起作用。
希望能对有所帮助!
在看到“存在多个设备”错误,以及两个离线手机显示时,我找到了这个问题。
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
adb kill-server
可以解决离线模拟器的问题。 - Morten Holmgaard在任何特定设备上运行shell的最佳方法是使用:
adb -s << emulator UDID >> shell
For Example:
adb -s emulator-5554 shell
$ 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
$ adb -s 646269f0 shell
用户@janot
已经在上面提到了这一点,但是我花了一些时间来过滤最佳解决方案。
有两个广泛的用例:
1)2个硬件设备相连,第一个是模拟器,另一个是设备。
解决方案:对于模拟器,使用adb -e shell....whatever-command
,对于设备,使用adb -d shell....whatever-command
。
2)n个设备通过USB/ADB-WiFi连接(所有模拟器或手机/平板电脑)。
解决方案:
步骤1)运行adb devices
。这将给出当前连接的设备列表(通过USB或ADBoverWiFI)
步骤2)现在运行adb -s <device-id/IP-address> shell....whatever-command
无论您有多少设备。
示例
要清除连接到wifi ADB上的设备上的应用程序数据,我会执行以下操作:
adb -s 172.16.34.89:5555 shell pm clear com.package-id
要清除连接到我的USB连接设备上的应用程序数据,我会执行以下操作:
adb -s 5210d21be2a5643d shell pm clear com.package-id
对于Windows系统,以下是一个快速的1行示例,说明如何在多台设备上安装文件。
FOR /F "skip=1" %x IN ('adb devices') DO start adb -s %x install -r myandroidapp.apk
FOR /F "skip=1" %%x IN ('adb devices') DO start adb -s %%x install -r myandroidapp.apk
install -r ....
替换为 %1
,然后将此脚本保存在您的路径中的某个位置。这样,您可以通过调用带有参数的脚本直接调用任何 adb 命令。例如,如果您将脚本命名为 adball
,则可以调用 adball uninstall myapp
。 - avalancha
adb -s 192.168.56.101:5555 shell
。 - Jason Hartleyadb -e shell
或adb emu <command>
。如果有多个模拟器运行,它们将失败,您需要使用-s
切换回去。 - Corey Ogburnshell
之前,您必须使用-s
选项。不能反过来做这件事是非常糟糕的用户体验... - baptxadb -s 192.168.178.81:45635 shell
。 - Wilco Verhoefshell
可以替换为您想在先前指定设备上执行的任何命令。在我的情况下,该命令如下所示:adb -s emulator-5554 reverse tcp:8081 tcp:8081
。 - gignu