How can I adb install an apk to multiple connected devices?
I have 7 devices plugged into my development machine.
Normally I do adb install <path to apk>
and can install to just a single device.
Now I would like to install my apk on all of my 7 connected devices. How can I do this in a single command? I'd like to run a script perhaps.
Solution 1:
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 ...
Comments suggest this might work better for newer versions:
adb devices | tail -n +2 | cut -sf 1 | xargs -iX adb -s X install ...
For Mac OSX(not tested on Linux):
adb devices | tail -n +2 | cut -sf 1 | xargs -I {} adb -s {} install ...
Solution 2:
The other answers were very useful however didn't quite do what I needed. I thought I'd post my solution (a shell script) in case it provides more clarity for other readers. It installs multiple apks and any mp4s
echo "Installatron"
for SERIAL in $(adb devices | tail -n +2 | cut -sf 1);
do
for APKLIST in $(ls *.apk);
do
echo "Installatroning $APKLIST on $SERIAL"
adb -s $SERIAL install $APKLIST
done
for MP4LIST in $(ls *.mp4);
do
echo "Installatroning $MP4LIST to $SERIAL"
adb -s $SERIAL push $MP4LIST sdcard/
done
done
echo "Installatron has left the building"
Thank you for all the other answers that got me to this point.
Solution 3:
Here's a functional one line command tailored from kichik's response (thanks!):
adb devices | tail -n +2 | cut -sf 1 | xargs -iX adb -s X install -r *.apk
But if you happen to be using Maven it's even simpler:
mvn android:deploy
Solution 4:
Another short option... I stumbled on this page to learn that the -s $SERIAL
has to come before the actual adb command! Thanks stackoverflow!
for SERIAL in $(adb devices | grep -v List | cut -f 1);
do `adb -s $SERIAL install -r /path/to/product.apk`;
done
Solution 5:
Generalized solution from Dave Owens to run any command on all devices:
for SERIAL in $(adb devices | grep -v List | cut -f 1);
do echo adb -s $SERIAL $@;
done
Put it in some script like "adb_all" and use same way as adb for single device.
Another good thing i've found is to fork background processes for each command, and wait for their completion:
for SERIAL in $(adb devices | grep -v List | cut -f 1);
do adb -s $SERIAL $@ &
done
for job in `jobs -p`
do wait $job
done
Then you can easily create a script to install app and start the activity
./adb_all_fork install myApp.apk
./adb_all_fork shell am start -a android.intent.action.MAIN -n my.package.app/.MainActivity