fix. seems to do gradle builds correctly, though those builds need a

lot of work still.
This commit is contained in:
Eric House 2016-05-23 08:39:51 -07:00
parent 8082a1e0dc
commit 06ef079af1

143
xwords4/android/scripts/find-and-gradle.sh Normal file → Executable file
View file

@ -1,60 +1,18 @@
#!/bin/sh #!/bin/sh
set -e -u set -e -u -x
APK_DIR="app/build/outputs/apk"
MANIFEST=AndroidManifest.xml MANIFEST=AndroidManifest.xml
XWORDS=org.eehouse.android.xw4 # XWORDS=org.eehouse.android.xw4
INSTALLS='' INSTALL=''
REINSTALL='' UNINSTALL=''
TASKS=''
VARIANTS=''
BUILDS=''
usage() { usage() {
[ $# -ge 1 ] && echo "ERROR: $1" [ $# -ge 1 ] && echo "ERROR: $1"
echo "usage: $0 [--task <gradle-task>]*" echo "usage: $0 [--install] [--reinstall] <cmds to gradle>"
echo " [--variant <variantName>|all]* # variant to install (defaults to all built, or all if not building)"
echo " [--[re]install debug|release]"
echo "examples"
echo "$0 --install --variant xw4 --build debug # install the debug build of xw4 (main) variant"
echo "$0 --reinstall --variant xw4 --build debug # install the debug build of xw4 (main) variant"
exit 1 exit 1
} }
checkInstallTarget() {
case $1 in
debug|release)
;;
*)
usage '"debug" or "release" expected'
;;
esac
}
getDevices() {
DEVICES="$(adb devices | grep '^.*\sdevice$' | awk '{print $1}')"
echo "getDevices() => $DEVICES" >&2
echo "$DEVICES"
}
setVariants() {
if [ -z "$VARIANTS" ]; then
VARIANTS="xw4"
fi
}
getApks() {
APKS=""
for VARIANT in $VARIANTS; do
for BUILD in $BUILDS; do
APKS="$APKS $(ls --sort=time $APK_DIR/app-${VARIANT}-${BUILD}.apk | head -n 1)"
done
done
echo $APKS >&2
echo $APKS
}
uninstall() { uninstall() {
adb devices | while read DEV TYPE; do adb devices | while read DEV TYPE; do
case "$TYPE" in case "$TYPE" in
@ -74,87 +32,44 @@ while [ $# -gt 0 ]; do
usage usage
;; ;;
--install) --install)
shift INSTALL=1
checkInstallTarget $1
INSTALL=$1
BUILDS="$BUILDS $1"
;; ;;
--reinstall) --reinstall)
shift UNINSTALL=1
checkInstallTarget $1 INSTALL=1
REINSTALL=$1
INSTALL=$1
;; ;;
--variant) *)
shift break
VARIANTS="$VARIANTS $1"
;;
--task)
shift
TASKS="$TASKS $1"
;;
*) # assumed to be the end of flags
usage "unexpected parameter $1"
;; ;;
esac esac
shift shift
done done
while [ ! -e $MANIFEST ]; do while [ ! -e ./gradlew ]; do
[ '/' = $(pwd) ] && usage "reached root without finding $MANIFEST" [ '/' = $(pwd) ] && usage "reached root without finding gradlew"
cd .. cd ..
done done
DIRNAME=$(basename $(pwd)) NOW_FILE=/tmp/NOW_$$
case $DIRNAME in touch $NOW_FILE
XWords4-bt)
PKG=xw4bt
;;
XWords4-dbg)
PKG=xw4dbg
;;
XWords4)
PKG=xw4
;;
*)
echo "running in unexpected directory $DIRNAME; hope that's ok"
;;
esac
# if we're running for the first time in this directory/variant, # If this fails, the "set -e" above means we won't try to install anything
# generate local.properties ./gradlew $*
# [ -e local.properties ] || ../scripts/setup_local_props.sh
# Mark "now" so can look for newer .apks later # Find the newest apk in the build output directory that's newer than our timestamp
TSFILE=/tmp/ts$$.stamp APK=''
touch $TSFILE APKS=$(find app/build/outputs/apk/ -name '*.apk' -a -newer $NOW_FILE)
if [ -n "$APKS" ]; then
APK=$(ls -t $APKS | head -n 1)
fi
[ -n "$APK" ] || usage "no new .apk files found; did the build succeed?"
if [ -n "$UNINSTALL" ]; then
if [ -n "$TASKS" ]; then LINE=$(aapt dump badging $APK | grep '^package')
./gradlew $TASKS PACKAGE=$(echo $LINE | sed "s,.*name='\([^' ]*\)'.*,\1,")
adb shell pm uninstall $PACKAGE
fi fi
if [ -z "$TASKS" -o 0 = "$?" ]; then if [ -n "$INSTALL" ]; then
setVariants adb-install.sh -p $APK
APKS=$(getApks)
DEVS="$(getDevices)"
for DEV in DEVS; do
for APK in $APKS; do
[ -n "$REINSTALL" ] && uninstall $APK $DEV
[ -n "$INSTALL" ] && installAndLaunch $APK $DEV
done
done
fi fi
# if [ -n "$UNINSTALL" ]; then
# uninstall
# fi
# if [ -n "$INSTALL" ]; then
# adb-install.sh -e -d
# fi
# if [ "$CMDS" != "${CMDS%%install}" ]; then
# adb shell am start -n org.eehouse.android.${PKG}/org.eehouse.android.${PKG}.GamesListActivity
# fi
rm -f $TSFILE