Skip to content

Instantly share code, notes, and snippets.

Created May 16, 2013 21:12
Show Gist options
  • Save anonymous/5595148 to your computer and use it in GitHub Desktop.
Save anonymous/5595148 to your computer and use it in GitHub Desktop.
A short script to perform auto install on multiple Android devices by watching a specific folder for an .apk write. Usage: ./continuous_deploy.sh com.example.package/.MainActivity
folder="bin/classes/"
package="$1"
inotifywait -m -q -e close_write "$folder" | while read f; do
# take only the filename
f=`awk '{print $3}' <<< "$f"`
# rebuild the full path
path="$folder$f"
# if it's not an apk or is the unaligned one, skip it
if [[ $f =~ ^.*unaligned\.apk$ || ! $f =~ ^.*apk$ ]]; then
echo "Skipping $f"
continue;
fi
# Get the list of device names. This ignores whether they're online or not.
devices=`adb devices | sed '1d' | awk '{print $1;}'`
echo "Sending $f.."
echo "$devices" | (parallel adb -s {} install -r "$path" | sed 's/^/ /') 2> /dev/null
echo "done"
# If we provided an activity name, start it on all devices
if [ $package ]; then
echo "Starting activity $package.."
echo "$devices" | (parallel adb -s {} shell am start "$package" | sed 's/^/ /') 2> /dev/null
echo "done"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment