我有一个简单的bash脚本,它遍历设备列表并运行adb shell命令到Android设备。代码如下:
echo "Displaying devices to be configured:"
adb devices | sed "1d ; $ d"
echo ""
echo "###########################"
echo "# #"
echo "# Starting configuration! #"
echo "# #"
echo "###########################"
echo ""
while read -r udid device usb product model device2; do
echo ""
echo $usb
echo ""
# INSTALL THE APPS
adb -s "$usb" install ./src/apps/1.apk
adb -s "$usb" install ./src/apps/quicksupport.apk
# SET WIFI OFF
adb -s "$usb" shell settings put global wifi_on 0
# SET SOUND TO 0
adb -s "$usb" shell service call audio 7 i32 3 i32 0 i32 1
# SET AUTO TIME ZONE OFF
adb -s "$usb" shell settings put global auto_time_zone 0
# SET INSTALL NON MARKET APPS ON
adb -s "$usb" shell settings put global install_non_market_apps 1
# REBOOT
adb -s "$usb" reboot
done < <(adb devices -l | sed "1d; $ d")
echo ""
echo "###########################"
echo "# #"
echo "# Configuration complete! #"
echo "# #"
echo "###########################"
echo ""
运行时,代码将成功运行一台设备上的所有配置。插入两个设备时,输出如下:
Displaying devices to be configured:
0123456789ABCDEF device
0123456789ABCDEF device
###########################
# #
# Starting configuration! #
# #
###########################
usb:336592896X
[100%] /data/local/tmp/1.apk
pkg: /data/local/tmp/1.apk
Failure [INSTALL_FAILED_ALREADY_EXISTS]
[100%] /data/local/tmp/quicksupport.apk
pkg: /data/local/tmp/quicksupport.apk
Failure [INSTALL_FAILED_ALREADY_EXISTS]
0123456789ABCDEF device usb:337641472X product:msm8960 model:msm8960 device:msm8960
Result: Parcel(00000000 '....')
###########################
# #
# Configuration complete! #
# #
###########################
似乎返回adb devices -l
命令的剩余部分而不是退出循环。这是bash的问题吗?这是adb的问题吗?我一直在努力解决这个问题。
注意:声音设置为零后,Result: Parcel(00000000 '....')
输出会立即发生。
注意:请注意Failure [INSTALL_FAILED_ALREADY_EXISTS]
,因为已经安装了应用程序。这不是我所关心的。
注意:发布adb devices -l | hexdump -C
00000000 4c 69 73 74 20 6f 66 20 64 65 76 69 63 65 73 20 |List of devices |
00000010 61 74 74 61 63 68 65 64 0a 30 31 32 33 34 35 36 |attached.0123456|
00000020 37 38 39 41 42 43 44 45 46 20 20 20 20 20 20 20 |789ABCDEF |
00000030 64 65 76 69 63 65 20 75 73 62 3a 34 33 37 33 38 |device usb:43738|
00000040 37 32 36 34 58 20 70 72 6f 64 75 63 74 3a 6d 73 |7264X product:ms|
00000050 6d 38 39 36 30 20 6d 6f 64 65 6c 3a 6d 73 6d 38 |m8960 model:msm8|
00000060 39 36 30 20 64 65 76 69 63 65 3a 6d 73 6d 38 39 |960 device:msm89|
00000070 36 30 0a 30 31 32 33 34 35 36 37 38 39 41 42 43 |60.0123456789ABC|
00000080 44 45 46 20 20 20 20 20 20 20 64 65 76 69 63 65 |DEF device|
00000090 20 75 73 62 3a 33 33 36 35 39 32 38 39 36 58 20 | usb:336592896X |
000000a0 70 72 6f 64 75 63 74 3a 6d 73 6d 38 39 36 30 20 |product:msm8960 |
000000b0 6d 6f 64 65 6c 3a 6d 73 6d 38 39 36 30 20 64 65 |model:msm8960 de|
000000c0 76 69 63 65 3a 6d 73 6d 38 39 36 30 0a 0a |vice:msm8960..|
000000ce
答案 0 :(得分:1)
这样做效率稍高且不易出错的方法:
DeviceConfig () {
# INSTALL THE APPS
adb -s $1 install ./src/apps/1.apk
adb -s $1 install ./src/apps/quicksupport.apk
# SET WIFI OFF
adb -s $1 shell settings put global wifi_on 0
...
adb -s $1 reboot
}
for usb in $(adb devices -l | awk '/ device usb:/{print $3}'); do DeviceConfig $usb; done