Skip to content Skip to sidebar Skip to footer

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 and can install to just a single device. Now I would like to install my apk on a

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);
dofor APKLIST in $(ls *.apk);
  doecho"Installatroning $APKLIST on $SERIAL"
  adb -s $SERIAL install $APKLISTdonefor MP4LIST in $(ls *.mp4);
  doecho"Installatroning $MP4LIST to $SERIAL"
  adb -s $SERIAL push $MP4LIST sdcard/
  donedoneecho"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);
doecho 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$@ &
donefor job in `jobs -p`
dowait$jobdone

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

Post a Comment for "How Can I Adb Install An Apk To Multiple Connected Devices?"