Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Deploys an .apk to the USB connected Android device. Starts the app, and grabs the logging events for that PID
#!/usr/bin/env bash
#set -e
PACKAGE=$1
if [ -z "$PACKAGE" ]; then
echo "You must pass a .apk as input!"
exit 1
fi
# Have the aapt in the PATH
AAPT=`which aapt`
if [ -z "$AAPT" ]; then
AAPT=$ANDROID_HOME/build-tools/23.0.2/aapt
if [ ! -e "$AAPT" ]; then
echo "AAPT not found:" $AAPT
exit 1
fi
fi
PACKAGENAME=`$AAPT dump badging "$PACKAGE" | grep package:\ name | cut -d \' -f 2`
echo "Package name = $PACKAGENAME"
echo "Uninstalling $PACKAGENAME"
adb uninstall $PACKAGENAME | sed -e 's/^/ /'
sleep 1
echo "Installing $PACKAGENAME"
adb install -r "$PACKAGE" | sed -e 's/^/ /'
echo "Launching $PACKAGENAME"
adb shell monkey -p $PACKAGENAME -c android.intent.category.LAUNCHER 1
sleep 1
PID=`adb shell ps | grep $PACKAGENAME | awk '{ print $2 }'`
echo PID=$PID
PIDCAT=$(which pidcat)
if [ "$LOGCAT_COLOR" != "" ]; then
echo "Using logcat-color"
$LOGCAT_COLOR
exit 0
fi
if [ "$PIDCAT" != "" ]; then
echo "Using pidcat"
$PIDCAT $PACKAGENAME
exit 0
fi
# Default adb log cat
echo "Using adb logcat"
RUN="adb logcat | grep $PID"
if [ "$PID" == "" ]; then
RUN="adb logcat"
fi
$RUN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.