I have 7 devices plugged into my development machine.
Normally I do adb install
and can install to just a single device.
Now
well its simple you can create a installapk.bat file that can do the job for multiple apk to multiple connected devices open installapk.bat with notepad++ and copy paste this code
FOR /F "skip=1" %%x IN ('adb devices') DO start adb -s %%x install -r Facebook.apk
FOR /F "skip=1" %%x IN ('adb devices') DO start adb -s %%x install -r Instagram.apk
FOR /F "skip=1" %%x IN ('adb devices') DO start adb -s %%x install -r Messenger.apk
FOR /F "skip=1" %%x IN ('adb devices') DO start adb -s %%x install -r Outlook.apk
FOR /F "skip=1" %%x IN ('adb devices') DO start adb -s %%x install -r Viber.apk
FOR /F "skip=1" %%x IN ('adb devices') DO start adb -s %%x install -r WhatsApp.apk
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.
I was wanting to log what was happening whilst installing, also needed it to be slightly comprehendable. Ended up with:
echo "Installing app on all connected devices."
adb devices | tail -n +2 | cut -sf 1 | xargs -I % sh -c '{ \
echo "Installing on %"; \
adb -s % \
install myApp.apk; \
; }'
Tested on Linux & Mac
Use this command-line utility: adb-foreach
-Get all the apk
stored in .apk
folder
-Install and replace app on devices
getBuild() {
for entry in .apk/*
do
echo "$entry"
done
return "$entry"
}
newBuild="$(getBuild)"
adb devices | while read line
do
if [! "$line" = ""] && ['echo $line | awk "{print $2}"' = "device"]
then
device='echo $line | awk "{print $1}"'
echo "adb -s $device install -r $newbuild"
adb -s $device install -r $newbuild
fi
done
I liked workingMatt's script but thought it could be improved a bit, here's my modified version:
#!/bin/bash
install_to_device(){
local prettyName=$(adb -s $1 shell getprop ro.product.model)
echo "Starting Installatroning on $prettyName"
for APKLIST in $(find . -name "*.apk" -not -name "*unaligned*");
do
echo "Installatroning $APKLIST on $prettyName"
adb -s $1 install -r $APKLIST
adb -s $1 shell am start -n com.foo.barr/.FirstActivity;
adb -s $1 shell input keyevent KEYCODE_WAKEUP
done
echo "Finished Installatroning on $prettyName"
}
echo "Installatron"
gradlew assembleProdDebug
for SERIAL in $(adb devices | tail -n +2 | cut -sf 1);
do
install_to_device $SERIAL&
done
My version does the same thing except:
There's a few ways it could still be improved but I'm quite happy with it.