使用 adb 命令一次性为多个设备安装 apk
- 3154
命令简介
adb install [-lrtsdg] (file)
把包文件推送到设备上并安装。
-l 锁定应用
-r 替换已存在的应用
-t 允许安装测试包
-s 安装到sd卡中
-d 可以安装低版本安装包
-p 安装部分应用
-g 授权所有运行时权限
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
adb uninstall [-k] (package)
卸载设备上的应用包,-k表示保存数据和缓存目录。
简易版
http://*.com/questions/8610733/how-can-i-adb-install-an-apk-to-multiple-connected-devices
You can use adb devices to get a list of connected devices and then run adb -s DEVICE_SERIAL_NUM install… for every device listed.
Something like (bash):
adb devices | tail -n +3 | cut -sf 1 -d " " | xargs -iX adb -s X install -r ...
- 1
Comments suggest this might work better for newer versions:
adb devices | tail -n +2 | cut -sf 1 | xargs -iX adb -s X install -r ...
- 1
For Mac OSX(not tested on Linux):
adb devices | tail -n +2 | cut -sf 1 | xargs -I {} adb -s {} install -r ...
- 1
可以使用下面的命令一次性安装多个apk:
adb install-multiple [-lrtsdpg] <file...>
- push this package file to the device and install it
(-l: forward lock application)
(-r: replace existing application)
(-t: allow test packages)
(-s: install application on sdcard)
(-d: allow version code downgrade (debuggable packages only))
(-p: partial application install)
(-g: grant all runtime permissions)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
Windows 环境下bat命令举例
在一个固定路径(例如:D:\bat_helper )文件夹下创建 multi_install.bat, D:\AAAAPPPPPPPKKKKKKK 路径是我存放 apk 的路径:
adb devices | tail -n +2 | cut -sf 1 | xargs -iX adb -s X install -r -d D:\AAAAPPPPPPPKKKKKKK\%1
- 1
创建 multi_install_util.bat, 我这里一次装了三个包 demo, local, pro:
start multi_install.bat Demo-%1.apk
start multi_install.bat Local8000-%1.apk
start multi_install.bat Product-%1.apk
- 1
- 2
- 3
可以在任意目录下创建下面的 bat文件,之后直接打开使用即可,更新版本也只需改个版本号:
d:
cd d:\bat_helper\
multi_install_util.bat V1.3.5
- 1
- 2
- 3
基础版
安装
随意找个地方,创建个 install_apk.bat
文件,修改内容为下:
@echo off
echo --------------------------------------------------------
echo start install %1
echo -----小米-------
adb -s 29e63c30 install -r %1
echo -----大三星-------
adb -s 42f7c21301979f2f install -r %1
echo --------------------------------------------------------
pause
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
设备可使用命令查看:
adb devices
- 1
然后将这个 install_apk.bat 所在的文件夹路径加到环境变量里,每次打开cmd 输入 install_apk + apk路径即可。
还可以在桌面上创建个 .bat 文件,内容:
@echo off
echo --------------------------------------------------------
install_apk D:\AAAAPPPPPPPKKKKKKK\Local.apk
pause
- 1
- 2
- 3
- 4
只要打开 bat 就可以自动安装给设备, 但要指定文件路径和apk名字。
卸载
创建uninstall_apk.bat
:
@echo off
echo --------------------------------------------------------
echo start uninstall %1
adb -s 9c10a497 uninstall %1
adb -s VS9804G5c12ef38 uninstall %1
adb -s 29e63c30 uninstall %1
adb -s ZY222WLGV4 uninstall %1
adb -s 42f7c21301979f2f uninstall %1
adb -s 4530c0df uninstall %1
echo --------------------------------------------------------
pause
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
uninstall_apk + 包名
卸载。
升级版
基础版每次添加新设备后,都要在文件里写入新的设备信息,比较麻烦。所以做了下修改,使用adb命令拿到 devices 信息后,再安装这些设备上,立马高大上了一大截,线性安装apk的bat 文件代码如下:
@echo off
echo --------------------------------------------------------
echo Get devices
adb devices > devices.txt
cat devices.txt
echo --------------------------------------------------------
echo start install %1
for /f "skip=1 tokens=1 delims= " %%i in (devices.txt) do (
adb -s %%i install -r %1
)
del devices.txt
echo --------------------------------------------------------
pause
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
%%i 是 devices 信息, %1 是传入的apk绝对路径。
并发安装需要创建一个新的bat 文件,用来分离安装命令,我起的名字是adb_install.bat:
echo start install apk to %1
adb -s %1 install -r %2
- 1
- 2
- 3
并发安装apk的bat命令是:
@echo off
echo --------------------------------------------------------
echo Get devices
adb devices > devices.txt
cat devices.txt
echo --------------------------------------------------------
echo start install %1
for /f "skip=1 tokens=1 delims= " %%i in (devices.txt) do (
start adb_install %%i %1
)
del devices.txt
echo --------------------------------------------------------
pause