如何使用 adb 从多个连接的设备上卸载 APK?

2022-09-03 16:29:23

adb uninstall <package name>连接 1 台设备时工作。

如何使此功能适用于连接的 5 台以上设备?


答案 1

这是我用来在所有设备上执行adb命令的简单脚本,应该在Linux和MacOsX下工作。

您可能需要使其适应您的开发环境。

#!/bin/bash
# Script adb+
# Usage
# You can run any command adb provide on all your current devices
# ./adb+ <command> is the equivalent of ./adb -s <serial number> <command>
#
# Examples
# ./adb+ version
# ./adb+ install apidemo.apk
# ./adb+ uninstall com.example.android.apis

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

答案 2

若要在连接多个设备时卸载程序包,可以使用以下命令。

  1. adb devices这将输出已连接项目的列表。

    List of devices         attached  
    1234c112fsasfl          device  
    53fsks22323233          device  
    192.168.56.101:5555     device
    
  2. adb -s your_device_key uninstall your_package_name.

    $ adb -s 1234c112fsasfl uninstall com.test.sample
    
    success - (if the device contains the apk with the specified package name)  
    failure - (if the device did not contain the apk with the specified package name)
    

推荐