Last active
June 18, 2019 07:24
-
-
Save mathiaswking/cd2f7cc4af95f77310b5817a33f9743a to your computer and use it in GitHub Desktop.
Deploys an .apk to the USB connected Android device. Starts the app, and grabs the logging events for that PID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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