-
-
Save christoffer/6636804 to your computer and use it in GitHub Desktop.
Dirty, but working, little bash script for day-to-day android development
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
#!/bin/bash | |
set -e | |
if [[ -z $ANDR_TARGET ]] | |
then | |
ANDR_TARGET="emulator" | |
fi | |
if [[ $ANDR_TARGET = "device" ]] | |
then | |
target_flag="-d" | |
maven_device_selector="usb" | |
elif [[ $ANDR_TARGET = "emulator" ]] | |
then | |
target_flag="-e" | |
maven_device_selector="emulator" | |
elif [[ ! -z $ANDR_TARGET ]] | |
then | |
echo "Unknown ANDR_TARGET: $ANDR_TARGET" | |
echo "Valid values: 'device' or 'emulator'" | |
exit | |
fi | |
default_package="com.readmill.android.dev" | |
if [ -z $ANDR_PACKAGE ] | |
then | |
ANDR_PACKAGE=$default_package | |
fi | |
books_dir=/mnt/sdcard/Android/data/${ANDR_PACKAGE}/files/books | |
function push { | |
echo "Pushing $1" | |
adb $target_flag push $1 $books_dir | |
} | |
function delete { | |
echo "Removing $1" | |
adb $target_flag shell "rm $books_dir/$1" | |
} | |
function list { | |
adb $target_flag shell "ls $books_dir" | |
} | |
# Clean redeploy | |
function redeploy { | |
mvn -pl app clean | |
mvn -Dandroid.device=${maven_device_selector} -pl app package android:deploy | |
} | |
# Quick deploy | |
function deploy { | |
mvn -Dandroid.device=${maven_device_selector} -DskipTests -DskipNdkBuild -pl app package android:deploy android:run | |
} | |
# Clean before running instrumentation | |
function reinstrument { | |
mvn -pl app clean install | |
mvn -pl it clean | |
instrument $1 | |
} | |
# Run instrumentation tests with an optional class filter. | |
# instrument "MyClass,AnotherClass" (runs tests from classes MyClass and AnotherClass) | |
# instrument (runs all tests) | |
# Note that this will use the currently installed (as in: mvn install) version of the | |
# app. Use reinstrument if you've made changes to the app that you need to test. | |
function instrument { | |
classfilter="" | |
if [ ! -z $1 ] | |
then | |
classfilter="-Dandroid.test.classes=$1 " | |
fi | |
mvn $classfilter-Dandroid.device=${maven_device_selector} -pl it package android:deploy android:instrument | |
} | |
function exit_with_usage { | |
echo "Usage: $0 list|delete|push|instrument|deploy|redeploy <arguments>" | |
exit | |
} | |
if [ $# -lt 1 ] | |
then | |
exit_with_usage | |
fi | |
function print_target { | |
case "$target_flag" in | |
-e ) echo "(=> Emulator)" ;; | |
-d ) echo "(=> Device)" ;; | |
esac | |
} | |
function print_package { | |
echo "(package: ${ANDR_PACKAGE})" | |
} | |
function main { | |
print_target | |
if [[ $ANDR_PACKAGE != $default_package ]] | |
then | |
print_package | |
fi | |
case "$1" in | |
list ) list | |
;; | |
delete ) delete $2 | |
;; | |
push ) push $2 | |
;; | |
deploy ) deploy | |
;; | |
redeploy ) redeploy | |
;; | |
reinstrument ) reinstrument $2 | |
;; | |
instrument ) instrument $2 | |
;; | |
* ) exit_with_usage | |
esac | |
} | |
main $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment