Skip to content

Instantly share code, notes, and snippets.

@grigory51
Created November 24, 2016 16:54
Show Gist options
  • Save grigory51/3233fdd004daddf71e7c6e931df31d85 to your computer and use it in GitHub Desktop.
Save grigory51/3233fdd004daddf71e7c6e931df31d85 to your computer and use it in GitHub Desktop.
Upload apk to all connected devices
#!/bin/bash
apk=$1
package=$2
if [ ! -f $apk ]; then
echo "APK $apk not exist"
exit 1
fi
if [ "$package" == '' ]; then
echo 'Package is empty, install will be skip'
fi
PATH=/opt/android-sdk/platform-tools:/opt/android-sdk/tools:$PATH
devices=$(adb devices | grep -v 'List of devices' | awk '{print $1}')
if [ "$devices" == "" ]; then
echo 'No devices connected, bye!'
exit 0
fi
for i in $devices; do
if [ "$i" != "" ]; then
echo "Install to $i"
adb -s $i install -r $apk
if [ $? -ne 0 ]; then
echo "Error during install apk to $i device"
continue
fi
echo "Done installation to $i"
if [ "$package" != '' ]; then
echo "Run app on $i"
adb shell monkey -p $package -c android.intent.category.LAUNCHER 1
if [ $? -ne 0 ]; then
echo "Error during run app on $i device"
continue
fi
echo "Done running app on $i"
fi
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment