I have 7 devices plugged into my development machine.
Normally I do adb install and can install to just a single device.
Now
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
Originated from here: Make The Previous Post A Mass APK Installer That Does Not Uses ADB Install-Multi Syntax
@echo off
:loop
::-------------------------- has argument ?
if ["%~1"]==[""] (
echo done.
goto end
)
::-------------------------- argument exist ?
if not exist %~s1 (
echo error "%~1" does not exist in file-system.
) else (
echo "%~1" exist
if exist %~s1\NUL (
echo "%~1" is a directory
) else (
echo "%~1" is a file! - time to install:
call adb install %~s1
)
)
::--------------------------
shift
goto loop
:end
pause
::: ##########################################################################
::: ## ##
::: ## 0. run: adb devices - to start the deamon and list your device ##
::: ## ##
::: ## 1. drag&drop ANY amount of files (APK) over this batch files, ##
::: ## ##
::: ## - it will install them one by one. ##
::: ## - it just checks if file exists. ##
::: ## - it does not checks if it is a valid APK package ##
::: ## - it does not checks if package-already-installed ##
::: ## - if there is an error you can always press [CTRL]+[C] ##
::: ## to stop the script, and continue from the next one, ##
::: ## some other time. ##
::: ## - the file is copied as DOS's 8.3 naming to you ##
::: ## don't need to worry about wrapping file names or renaming ##
::: ## them, just drag&drop them over this batch. ##
::: ## ##
::: ## Elad Karako 1/1/2016 ##
::: ## http://icompile.eladkarako.com ##
::: ##########################################################################
Here is bash for install and run apk on all connected devices
Using
nick@nickolay:/home/workspace/MyProject$ > bash path/to/installAndRunApk.sh
installAndRunApk.sh
#!/usr/bin/env bash
#--------find apk---------
apkFile=$(find -name '*.apk' -print | grep -oP '(?<=.).*(.apk)')
#--------find apkFilePath---------
if test -z "apkFile"
then
echo "apkFile: is NULL"
exit 0;
fi
echo "apkFile: ${apkFile}"
apkFilePath=$(pwd)${apkFile}
echo "apk file path: ${apkFilePath}"
#--------install---------
if test -z "$apkFilePath"
then
echo "apkFilePath: is NULL"
exit 0;
fi
echo "adb install -t -r ${apkFilePath}"
for SERIAL in $(adb devices | grep -v List | cut -f 1);
do `adb -s ${SERIAL} install -t -r ${apkFilePath}`;
done
#--------get applicationId---------
echo "aapt dump badging ${apkFilePath} | grep -oP '(?<=package: name=).*(?=versionCode)'"
applicationId=$(aapt dump badging ${apkFilePath} | grep -oP '(?<=package: name=).*(?=versionCode)')
echo "applicationId: is ${applicationId}"
#--------launch---------
if test -z "$applicationId"
then
echo "applicationId: is NULL"
exit 0;
fi
echo "____________________START_APPLICATION_ID________________________"
echo "applicationId: ${applicationId}"
echo "____________________END_APPLICATION_ID__________________________"
echo "____________________START_LAUNCHER______________________________"
for SERIAL in $(adb devices | grep -v List | cut -f 1);
do `adb -s ${SERIAL} shell monkey -p ${applicationId} -c android.intent.category.LAUNCHER 1`;
done
echo "____________________END_LAUNCHER________________________________"
PowerShell solution
function global:adba() {
$deviceIds = iex "adb devices" | select -skip 1 | %{$_.Split([char]0x9)[0].Trim() } | where {$_ -ne "" }
foreach ($deviceId in $deviceIds) {
Echo ("--Executing on device " + $deviceId + ":---")
iex ("adb -s $deviceId " + $args)
}
}
Put this in your profile file (notepad $PROFILE), restart your shell and you can invoke installations with :
adba install yourApp.apk
This command works perfect
adb devices | awk 'NR>1{print $1}' | xargs -n1 -I% adb -s % install foo.apk
With this script you can just do:
adb+ install <path to apk>
Clean, simple.