adb uninstall <package name>
works when 1 device is connected.
How can I make this work for 5+ devices that are connected?
adb uninstall <package name>
works when 1 device is connected.
How can I make this work for 5+ devices that are connected?
To uninstall the package when multiple devices are connected, you can use the following commands.
adb devices
This will output a list of connected items.
List of devices attached
1234c112fsasfl device
53fsks22323233 device
192.168.56.101:5555 device
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)
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
I realise that this question already has an accepted answer, but:
for d in $(adb devices -l | sed '1d' | sed '$d' | awk '{print $1}'); do adb -s $d uninstall your.pkg.id.here; done
The sub-command first:
Then the outer for-loop:
In JAVA:
public class main {
private final static String packageName = "com.mypackage.xxx";
public static void main(String[] args) throws IOException, InterruptedException {
new main().doStuff();
}
private void doStuff() throws IOException, InterruptedException {
Runtime rt = Runtime.getRuntime();
String command = "adb devices -l";
Process pr = rt.exec(command);
ArrayList<HashMap<String, String>> devices = new ArrayList<HashMap<String, String>>();
BufferedReader bf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String l = "";
while ((l = bf.readLine()) != null) {
String[] res = l.split("\\s{2,}");
if (res.length == 2) {
HashMap<String, String> device = new HashMap<String, String>();
device.put("serial", res[0]);
device.put("name", res[1]);
devices.add(device);
}
}
String commandUninstall = "adb -s %s uninstall %s";
for (HashMap<String, String> map : devices) {
String serial = map.get("serial");
String finalCommanUnisntall = String.format(commandUninstall, serial, packageName);
System.out.println(finalCommanUnisntall);
Process pr2 = rt.exec(finalCommanUnisntall);
BufferedReader bf2 = new BufferedReader(new InputStreamReader(pr2.getInputStream()));
String l2 = "";
while ((l2 = bf2.readLine()) != null) {
System.out.println(l2);
}
}
}
}
You would have to write a script that calls adb multiple times and on each run it specify the serial number for each attached device with the -s switch.
An alternative is to use the Android Maven plugin which can just iterate through all attached devices (or emulators or devices only). See the interaction with devices chapter in the book Maven: The Complete Reference I wrote.
Also not that the multi device interaction of the Android Maven plugin also works for push, pull, install and running tests..