Skip to content

Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.

Merge PR #630: launcher: ask the TV's SDK level before building (minSdk preflight), and answer #576

Gathin234606f36cb4e7
diff --cc launcher/build-and-install.sh
index 661ab3e0c,d28b33d56..3ace95d0a
--- a/launcher/build-and-install.sh
+++ b/launcher/build-and-install.sh
@@@ -3,23 -3,24 +3,39 @@@
set -euo pipefail
cd "$(dirname "$0")"
: "${TV_HOST:?set TV_HOST to the TV IP address, e.g. TV_HOST=192.168.1.50 $0}"
+ TOOLS="$(cd ../tools && pwd)" # absolute, so the venv's Python doesn't warn about "../" in its prefix
+ PY=$TOOLS/venv/bin/python
+ [ -x "$PY" ] || PY=$TOOLS/venv/Scripts/python.exe
+ export MSYS_NO_PATHCONV=1
+ # Below minSdk, `pm install` refuses the APK with INSTALL_FAILED_OLDER_SDK - and only after gradle has
+ # spent a minute building and b64push has pushed the APK to the TV (#576). Ask the TV first. The
+ # number comes from the build file, so it follows the launcher instead of a hard-coded copy here.
+ MIN_SDK=$(sed -n 's/^[[:space:]]*minSdk[[:space:]][[:space:]]*\([0-9]\{1,3\}\)[[:space:]]*$/\1/p' app/build.gradle 2>/dev/null | head -n 1 || true)
+ TV_SDK=$("$PY" -I "$TOOLS/tv.py" 'getprop ro.build.version.sdk' 2>/dev/null | tr -dc '0-9' || true)
+ if [ -n "$MIN_SDK" ] && [ -n "$TV_SDK" ] && [ "$TV_SDK" -lt "$MIN_SDK" ]; then
+ echo "ERROR: this TV runs SDK $TV_SDK and the launcher is built with minSdk $MIN_SDK (app/build.gradle)," >&2
+ echo "so pm install would answer INSTALL_FAILED_OLDER_SDK. Nothing was built, pushed or disabled." >&2
+ echo "The debloat half of the repo still applies to that set, from its own home screen; the launcher" >&2
+ echo "half would need your own build with a lower minSdk (docs/TROUBLESHOOTING.md)." >&2
+ exit 1
+ fi
# macOS: java_home or Homebrew; Linux: the java on PATH.
-export JAVA_HOME="${JAVA_HOME:-$(/usr/libexec/java_home -v 17 2>/dev/null || { [ -d /opt/homebrew/opt/openjdk@17 ] && echo /opt/homebrew/opt/openjdk@17; } || java -XshowSettings:properties -version 2>&1 | awk '/java.home/ {print $3}')}"
+# `/usr/libexec/java_home -v 17` means "17 or newer", so on a Mac whose only JDK is newer it prints
+# that one and exits 0, and the Homebrew fallback below never runs. Gradle 8.9 then stops with
+# "Unsupported class file major version" (68 for JDK 24) before it reads a line of this project.
+# Homebrew's openjdk@17 is keg-only and is never registered where java_home would find it, so check
+# the version it answers with and fall through when it is not a 17. `java -version` goes to a
+# variable rather than through `grep -q`, whose early exit can SIGPIPE the JVM under `set -o pipefail`.
+if [ -z "${JAVA_HOME:-}" ]; then
+ JH="$(/usr/libexec/java_home -v 17 2>/dev/null || true)"
+ if [ -n "$JH" ]; then
+ case "$("$JH/bin/java" -version 2>&1 || true)" in *'version "17.'*) ;; *) JH="" ;; esac
+ fi
+ if [ -z "$JH" ] && [ -d /opt/homebrew/opt/openjdk@17 ]; then JH=/opt/homebrew/opt/openjdk@17; fi
+ if [ -z "$JH" ]; then JH="$(java -XshowSettings:properties -version 2>&1 | awk '/java.home/ {print $3}')"; fi
+ JAVA_HOME="$JH"
+fi
+export JAVA_HOME
# Android Studio's default SDK location on macOS, then on Linux, then Homebrew's command-line tools.
export ANDROID_HOME="${ANDROID_HOME:-$(for d in ~/Library/Android/sdk ~/Android/Sdk; do [ -d "$d" ] && echo "$d" && break; done)}"
export ANDROID_HOME="${ANDROID_HOME:-/opt/homebrew/share/android-commandlinetools}"