clone

a desktop tv and program guide for over-the-air broadcasts: what's on air, what your tuner gets, live tv, recordings

main
airwaves / scripts / android.sh
android.sh 2.2K executable
1#!/bin/sh2# Build the Airwaves Android TV app (debug) and install and start it on a TV.3# scripts/android.sh 192.168.1.50:5555 [server]4# The device is an adb serial: a TV's wireless debugging address (connected5# first if adb isn't already; pair it once as android/README.md says) or any6# serial from `adb devices`. With server (nas:8089, http://192.168.1.20:8089)7# the app is pointed at it; without, it keeps its setting or asks at first run.8# Builds the working tree. Needs a JDK 17 or later and the Android SDK9# (ANDROID_HOME, or sdk.dir in android/local.properties); both are looked10# for in the usual places when unset.11set -eu12usage='usage: android.sh <device> [server]'13device=${1:?$usage}14server=${2:-}15root=$(cd "$(dirname "$0")/.." && pwd)16app=dev.airwaves.tv17apk=$root/android/app/build/outputs/apk/debug/app-debug.apk1819if [ -z "${ANDROID_HOME:-}" ] && [ ! -f "$root/android/local.properties" ]; then20 for sdk in "${ANDROID_SDK_ROOT:-}" "$HOME/Library/Android/sdk" "$HOME/Android/Sdk" \21 /opt/homebrew/share/android-commandlinetools /usr/local/share/android-commandlinetools; do22 if [ -n "$sdk" ] && [ -d "$sdk/platforms" ]; then23 ANDROID_HOME=$sdk24 export ANDROID_HOME25 break26 fi27 done28fi29if [ -z "${JAVA_HOME:-}" ] && ! java -version >/dev/null 2>&1; then30 for jdk in /opt/homebrew/opt/openjdk@21 /opt/homebrew/opt/openjdk@17 /opt/homebrew/opt/openjdk \31 /usr/lib/jvm/java-21-openjdk* /usr/lib/jvm/java-17-openjdk*; do32 if [ -x "$jdk/bin/java" ]; then33 JAVA_HOME=$jdk34 export JAVA_HOME35 break36 fi37 done38fi39adb=adb40command -v adb >/dev/null 2>&1 || adb=${ANDROID_HOME:?no adb: set ANDROID_HOME}/platform-tools/adb4142echo "building $(sed -n 's/.*versionName = "\(.*\)"/\1/p' "$root/android/app/build.gradle.kts") at $(git -C "$root" log -1 --format='%h %s')"43(cd "$root/android" && ./gradlew --quiet assembleDebug)4445case $device in46 *:*) "$adb" devices | awk -v d="$device" '$1 == d && $2 == "device" { up = 1 } END { exit !up }' ||47 "$adb" connect "$device" ;;48esac49"$adb" -s "$device" install -r "$apk"50if [ -n "$server" ]; then51 "$adb" -s "$device" shell am start -n "$app/.MainActivity" --es server "'$server'"52else53 "$adb" -s "$device" shell am start -n "$app/.MainActivity"54fi