Skip to content

Instantly share code, notes, and snippets.

@bafu
Created July 7, 2016 16:39
Show Gist options
  • Save bafu/c28b3fcec5934d56a00b394c09f3ed06 to your computer and use it in GitHub Desktop.
Save bafu/c28b3fcec5934d56a00b394c09f3ed06 to your computer and use it in GitHub Desktop.
Install and launch APK for testing.
#!/bin/bash
#
# Install and launch built Android APK into the physical target
# connected by an USB cable. If there is an existing APK installed,
# it will be removed first.
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
which aapt > /dev/null
if [ "$?" != "0" ]; then
echo "ERROR: Command aapt is not available. Please install it first."
exit 1
fi
if [ "$1" = "" ]; then
echo "Usage: apk-installer APKPATH"
exit 1
fi
APK_PATH="$1"
APP_PACKAGE="$(aapt dump badging $APK_PATH | grep package | cut -d \' -f 2)"
APP_ACTIVITY="$(aapt dump badging $APK_PATH | grep launchable-activity | cut -d \' -f 2)"
echo "Stop activity"
adb shell "am force-stop $APP_PACKAGE"
echo "Uninstall APK"
adb uninstall $APP_PACKAGE
echo "Install APK"
adb install $APK_PATH
echo "Start activity"
adb shell "am start -n $APP_PACKAGE/$APP_ACTIVITY"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment