$ 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
当前回答
你可以使用它来连接你的特定设备:
* 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
也许这能帮到别人
其他回答
创建一个Bash (tools.sh)从设备(或模拟器)中选择一个串行:
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
然后在另一个选项中可以使用adb -s(全局选项-s使用设备与给定的序列号,覆盖$ANDROID_SERIAL):
adb -s ${device} <command>
我在MacOS终端上测试了这段代码,但我认为它可以跨Git Bash终端在windows上使用。
还记得在.bash_profile文件中配置环境变量和Android SDK路径:
export ANDROID_HOME="/usr/local/opt/android-sdk/"
export PATH="$ANDROID_HOME/platform-tools:$PATH"
export PATH="$ANDROID_HOME/tools:$PATH"
在你的仿真器中安装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>必须在安装命令之前,否则它将不起作用。
希望这能帮助到一些人!
为了方便起见,我们可以创建运行配置,设置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,命令被作为“脚本参数”传递。
你可以使用它来连接你的特定设备:
* 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
也许这能帮到别人
下面是我为自己编写的shell脚本:
#! /bin/sh
for device in `adb devices | awk '{print $1}'`; do
if [ ! "$device" = "" ] && [ ! "$device" = "List" ]
then
echo " "
echo "adb -s $device $@"
echo "------------------------------------------------------"
adb -s $device $@
fi
done