#!/usr/bin/env bash # # Build and test this fork directly on the phone, from Termux. # See CLAUDE.md ("Building on the phone itself") for the SDK setup this expects. # # The debug build is the package "de.mm20.launcher2.debug": a separate install from the # real launcher ("de.mm20.launcher2.release") with its own, initially empty, data directory. set -euo pipefail REPO=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) PKG=de.mm20.launcher2.debug ACTIVITY=de.mm20.launcher2.ui.launcher.LauncherActivity DEBUG_APK=$REPO/app/app/build/outputs/apk/default/debug/app-default-debug.apk RELEASE_APK=$REPO/app/app/build/outputs/apk/default/release/app-default-release.apk usage() { cat <<'EOF' Usage: scripts/ondevice.sh build assemble the debug APK install build, then install the debug APK (needs root) start launch the installed debug build logs follow logcat of the running debug build crash print the newest crash report for the debug build release assemble the signed release APK: same package and key as the launcher installed from Obtanium, so it installs over it and keeps all data EOF } # Termux ships JDK 21 in $PREFIX; on other machines JAVA_HOME has to be set already. if [ -z "${JAVA_HOME:-}" ] && [ -n "${PREFIX:-}" ] && [ -d "$PREFIX/lib/jvm/java-21-openjdk" ]; then export JAVA_HOME=$PREFIX/lib/jvm/java-21-openjdk fi gradle() { ( cd "$REPO" && ./gradlew --console=plain "$@" ) } # Long builds outlive the screen lock; keep the CPU awake until they are done. wake() { command -v termux-wake-lock >/dev/null && termux-wake-lock || true } build_debug() { wake gradle :app:app:assembleDefaultDebug ls -l "$DEBUG_APK" } # Every su -c argument below mixes two quoting levels: the single quoted parts are handed # to the root shell as-is (so $( ) and $pid are expanded there), the "..." parts are # expanded here. case "${1:-}" in build) build_debug ;; install) build_debug # Termux cannot use pm itself; root can, and can read the APK from ~/sources. su -c "pm install -r -d '$DEBUG_APK'" ;; start) su -c "am start -n $PKG/$ACTIVITY" ;; logs) su -c 'pid=$(pidof '"$PKG"') if [ -z "$pid" ]; then echo "not running - start it first (scripts/ondevice.sh start)" >&2 exit 1 fi exec logcat --pid=$pid' ;; crash) su -c 'for f in $(ls -t /data/system/dropbox/data_app_crash@*.txt 2>/dev/null | head -30); do if grep -q '"$PKG"' "$f"; then echo "== $f"; cat "$f"; break; fi done' ;; release) wake gradle :app:app:assembleDefaultRelease ls -l "$RELEASE_APK" ;; *) usage exit 1 ;; esac