Skip to content

Instantly share code, notes, and snippets.

@pulimento
Last active March 23, 2022 16:09
Show Gist options
  • Save pulimento/0e1d0d40d7a2515851def51fb2c32e19 to your computer and use it in GitHub Desktop.
Save pulimento/0e1d0d40d7a2515851def51fb2c32e19 to your computer and use it in GitHub Desktop.
Install an APK to multiple devices
write-host ('### Multiple devices installer ###') -foreground "Green"
$package_name = '<insert_your_package_name_here>'
# Search for apk to install
$debug_regex = '[Dd]ebug$'
$release_regex = '[Rr]elease$'
$apk = @(Get-ChildItem -include *.apk -Recurse | Where-Object { $_.Name -match 'Signed.apk$' -and $_.DirectoryName -match $debug_regex })
if( $apk.length -ge 2 )
{
write-host ('Warning! More than one APK candidate to install. Exiting...') -foreground "Red"
exit
}
if ($apk.length -eq 0 )
{
write-host ('Error! There are no APK candidates to install. Please make sure your project has been built. Exiting...') -foreground "Red"
exit
}
write-host ('### APK to install: ' + $apk) -foreground "Blue"
# Install apk in all ADB devices
foreach($SERIAL in $(adb devices | grep -v List | cut -f 1))
{
if (-not ([string]::IsNullOrEmpty($SERIAL)))
{
write-host ('### Device: ' + $SERIAL) -foreground "Cyan"
@(adb -s $SERIAL install -r $apk)
}
}
# Kill processes
write-host 'Killing process not needed, installed with --replace'
# Launch main activity
write-host ('Launching app...') -foreground "Blue"
foreach($SERIAL in $(adb devices | grep -v List | cut -f 1))
{
if (-not ([string]::IsNullOrEmpty($SERIAL)))
{
write-host ('### Device: ' + $SERIAL) -foreground "Cyan"
adb -s $SERIAL shell monkey -p $package_name 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment