Sheehan Alam Sheehan Alam - 7 months ago 38
Bash Question

How can I use adb to uninstall an APK from multiple connected devices?

adb uninstall <package name>
works when 1 device is connected.

How can I make this work for 5+ devices that are connected?

Answer

Here is a simple script I use to execute adb commands over all my devices , should work under Linux and MacOsX .

You might need to adapt it to your development environment .

#!/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