Skip to content

Instantly share code, notes, and snippets.

@erikusaj
Created October 24, 2018 07:42
Show Gist options
  • Save erikusaj/63457274eb676a028dfd4d056a8dc9ec to your computer and use it in GitHub Desktop.
Save erikusaj/63457274eb676a028dfd4d056a8dc9ec to your computer and use it in GitHub Desktop.
#!/bin/bash
# push apk to Android device, try to find launchable activity
# if this fails use monkey
if [ "$1" == "" ]; then
echo -e "Missing parameter: apk file"
else
echo -e "Please wait, while (re-)installing APK to device... \n"
adb install -r $1
echo -e "Finding what can be launched ... \n"
pkg=$(aapt dump badging $1|awk -F" " '/package/ {print $2}'|awk -F"'" '/name=/ {print $2}')
act=$(aapt dump badging $1|awk -F" " '/launchable-activity/ {print $2}'|awk -F"'" '/name=/ {print $2}')
# check for errors
pkgError="$(echo $pkg | grep ERROR)"
actError="$(echo $act | grep ERROR)"
if [[ pkgError != "" && actError != "" ]]; then
launchError="Error findign activity"
else
# no errors try to launch ...
echo -e "Launching activity\n"
launchError="$(adb shell am start -n $pkg/$act | grep Error)"
fi
# if errors launch wiht monkey
if [ "$launchError" != "" ]; then
echo -e "Error launching activity:\n"
echo -e "$launchError\n"
echo -e "\n\nMonkey business ...\n"
adb shell monkey -p $pkg 1
fi
adb shell dumpsys package $pkg | grep versionName
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment