How to use ADB Shell when Multiple Devices are connected? Fails with “error: more than one device and emulator”
1 $ adb --help
<但是>
...
1 -s SERIAL use device with given serial (overrides $ANDROID_SERIAL)
<但是>
...
1
2
3
4 $ adb devices
List of devices attached
emulator-5554 device
7f1c864e device
<但是>
...
1
2 $ adb shell -s 7f1c864e
error: more than one device and emulator
<但是>
?
在命令之前使用
1 | adb -s 7f1c864e shell |
另请参阅http://developer.android.com/tools/help/adb.html#directingcommands
如果您懒得输入完整ID,此命令将在大多数情况下为您提供帮助。
来自http://developer.android.com/tools/help/adb.html#commandsummary:
-d - Direct an adb command to the only attached USB device. Returns an error when more than one USB device is attached.
-e - Direct an adb command to the only running emulator. Returns an error when more than one emulator is running.
另一种方法是将环境变量ANDROID_SERIAL设置为相关的序列,这里假设您使用的是Windows:
1 2 3 | set ANDROID_SERIAL="7f1c864e" echo %ANDROID_SERIAL% "7f1c864e" |
然后你可以使用
我看到"多个设备"错误后发现了这个问题,其中有2个离线手机显示:
1 2 3 4 5 | C:\Program Files (x86)\Android\android-sdk\android-tools>adb devices List of devices attached SH436WM01785 offline SH436WM01785 offline SH436WM01785 sideload |
如果只连接了一个设备,请运行以下命令以消除脱机连接:
1 2 | adb kill-server adb devices |
当连接多个设备时,这个要点将为您显示菜单做大部分工作:
1 2 3 4 | $ 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: |
为避免键入,您只需创建一个包含设备选择的别名,如此处所述。
用户
有两个广泛的用例:
1)连接2个硬件,首先是仿真器,另一个是设备。
解决方案:
2)通过USB / ADB-WiFi连接了许多设备(所有仿真器或电话/平板电脑):
解:
Step1)运行
Step2)现在运行
无论你有多少设备。
清除在无线ADB上连接的设备上的应用数据的示例我将执行:
要清除我的usb连接设备上连接的应用数据,我会执行:
在所有连接的设备上运行adb命令
创建一个bash(adb +)
1 2 3 4 5 6 7 8 | 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
用它
adb + // +命令
要在其中一个模拟器上安装apk:
首先获取设备列表:
1 2 3 4 | -> adb devices List of devices attached 25sdfsfb3801745eg device emulator-0954 device |
然后使用
1 2 3 4 | -> adb -s"25sdfsfb3801745eg" install"C:\Users\joel.joel\Downloads elease.apk" Performing Streamed Install Success |
希望这有助于某人!
对于Windows,这是一个如何在多个设备上安装文件的快速1个线性示例
1 | FOR /F"skip=1" %x IN ('adb devices') DO start adb -s %x install -r myandroidapp.apk |
如果您计划将其包含在批处理文件中,请将%x替换为%% x,如下所示
1 | FOR /F"skip=1" %%x IN ('adb devices') DO start adb -s %%x install -r myandroidapp.apk |
创建一个Bash(tools.sh)以从设备(或模拟器)中选择一个序列:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | clear; echo"===================================================================================================="; echo" ADB DEVICES"; echo"===================================================================================================="; echo""; adb_devices=( $(adb devices | grep -v devices | grep device | cut -f 1)#$(adb devices | grep -v devices | grep device | cut -f 2) ); if [ $((${#adb_devices[@]})) -eq"1" ] && ["${adb_devices[0]}" =="#" ] then echo"No device found"; echo""; echo"===================================================================================================="; device="" // Call Main Menu function fxMenu; else read -p"$( f=0 for dev in"${adb_devices[@]}"; do nm="$(echo ${dev} | cut -f1 -d#)"; tp="$(echo ${dev} | cut -f2 -d#)"; echo" $((++f)). ${nm} [${tp}]"; done echo""; echo" 0. Quit" echo""; echo"===================================================================================================="; echo""; echo ' Please select a device: ' )" selection error="You think it's over just because I am dead. It's not over. The games have just begun."; // Call Validation Numbers fxValidationNumberMenu ${#adb_devices[@]} ${selection}"${error}" case"${selection}" in 0) // Call Main Menu function fxMenu; *) device="$(echo ${adb_devices[$((selection-1))]} | cut -f1 -d#)"; // Call Main Menu function fxMenu; esac fi |
然后在另一个选项中可以使用
1 | adb -s ${device} <command> |
我在MacOS终端上测试了这段代码,但我认为它可以在Git Bash Terminal的Windows上使用。
还要记得在
1 2 3 | export ANDROID_HOME="/usr/local/opt/android-sdk/" export PATH="$ANDROID_HOME/platform-tools:$PATH" export PATH="$ANDROID_HOME/tools:$PATH" |
在任何特定设备上运行shell的最佳方法是使用:
1 2 3 4 | adb -s << emulator UDID >> shell For Example: adb -s emulator-5554 shell |
100%工作
请大肆宣传