Skip to content

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

tools: build the launcher and add-ons in Docker; SKIP_BUILD=1 installs that build

nitzzzu525555219652
diff --git a/README.md b/README.md
index 92a40a7ab..e88783496 100644
--- a/README.md
+++ b/README.md
@@ -522,6 +522,7 @@ tools/theme.sh themes/aurora # push a theme; --r
| Tool | What it does |
|---|---|
| [`tools/tv.py`](tools/tv.py) | Pure-Python ADB client: shell, batch, push, pull, reboot, and screenshots, optionally pressing remote keys first. Works where the stock `adb` binary is blocked. Optional [paired Google ADB backend](tools/native-adb.md) for encrypted Wireless debugging. |
+| [`tools/docker-build.sh`](tools/docker-build.sh) | Builds the launcher or an add-on in Docker (JDK 17, Android SDK 34), so this computer needs nothing but Docker. Install the result with `SKIP_BUILD=1`. [Guide](tools/docker-build.md). |
| [`tools/b64push.py`](tools/b64push.py) | Uploads large files such as APKs in base64 chunks and verifies the checksum. |
| [`tools/relay.py`](tools/relay.py) | Forwards a local port to the TV's ADB port, for assistants whose sandbox can't reach your network. Listens on this computer only. [Guide](tools/relay.md). |
| [`tools/disable.sh`](tools/disable.sh), [`restore.sh`](tools/restore.sh) | Apply or undo a debloat list, the undo from the state recorded before the change. |
diff --git a/launcher/build-and-install.ps1 b/launcher/build-and-install.ps1
index df940f294..b04f3c31c 100644
--- a/launcher/build-and-install.ps1
+++ b/launcher/build-and-install.ps1
@@ -22,19 +22,24 @@ if (-not $TvHost) { throw 'pass -TvHost <tv ip> or set $env:TV_HOST' }
$env:TV_HOST = $TvHost
Set-Location $PSScriptRoot
-if (-not $env:JAVA_HOME -or -not (Test-Path "$env:JAVA_HOME\bin\java.exe")) {
- $jbr = Get-ChildItem 'C:\Program Files\Android' -Directory -ErrorAction SilentlyContinue |
- ForEach-Object { Join-Path $_.FullName 'jbr' } | Where-Object { Test-Path "$_\bin\java.exe" } | Select-Object -First 1
- if (-not $jbr) { throw 'Set JAVA_HOME to a JDK 17+ (Android Studio ships one in its jbr folder)' }
- $env:JAVA_HOME = $jbr
-}
-$sdk = if ($env:ANDROID_HOME) { $env:ANDROID_HOME } else { "$env:LOCALAPPDATA\Android\Sdk" }
-if (-not (Test-Path local.properties)) {
- "sdk.dir=$($sdk -replace '\\', '\\')" | Out-File -Encoding ascii local.properties
-}
+# SKIP_BUILD=1 installs the APK already built (tools\docker-build.ps1 builds it in Docker, with no JDK here).
+if ($env:SKIP_BUILD -ne '1') {
+ if (-not $env:JAVA_HOME -or -not (Test-Path "$env:JAVA_HOME\bin\java.exe")) {
+ $jbr = Get-ChildItem 'C:\Program Files\Android' -Directory -ErrorAction SilentlyContinue |
+ ForEach-Object { Join-Path $_.FullName 'jbr' } | Where-Object { Test-Path "$_\bin\java.exe" } | Select-Object -First 1
+ if (-not $jbr) { throw 'Set JAVA_HOME to a JDK 17+ (Android Studio ships one in its jbr folder)' }
+ $env:JAVA_HOME = $jbr
+ }
+ $sdk = if ($env:ANDROID_HOME) { $env:ANDROID_HOME } else { "$env:LOCALAPPDATA\Android\Sdk" }
+ if (-not (Test-Path local.properties)) {
+ "sdk.dir=$($sdk -replace '\\', '\\')" | Out-File -Encoding ascii local.properties
+ }
-.\gradlew.bat assembleRelease -q --console=plain
-if ($LASTEXITCODE -ne 0) { throw 'Gradle build failed' }
+ .\gradlew.bat assembleRelease -q --console=plain
+ if ($LASTEXITCODE -ne 0) { throw 'Gradle build failed' }
+} elseif (-not (Test-Path 'app\build\outputs\apk\release\app-release.apk')) {
+ throw 'SKIP_BUILD=1 but there is no app\build\outputs\apk\release\app-release.apk; build it first (tools\docker-build.ps1)'
+}
$py = '..\tools\venv\Scripts\python.exe'
# Which app owns Home differs by build; ask the TV, but only accept a launcher we recognise (the answer
diff --git a/launcher/build-and-install.sh b/launcher/build-and-install.sh
index 2942e9fb7..68f948583 100755
--- a/launcher/build-and-install.sh
+++ b/launcher/build-and-install.sh
@@ -21,6 +21,8 @@ if [ -n "$MIN_SDK" ] && [ -n "$TV_SDK" ] && [ "$TV_SDK" -lt "$MIN_SDK" ]; then
echo "half would need your own build with a lower minSdk (docs/TROUBLESHOOTING.md)." >&2
exit 1
fi
+# SKIP_BUILD=1 installs the APK already built (tools/docker-build.sh builds it in Docker, with no JDK here).
+if [ "${SKIP_BUILD:-}" != 1 ]; then
# macOS: java_home or Homebrew; Linux: the java on PATH.
# `/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
@@ -51,6 +53,10 @@ export PATH="$JAVA_HOME/bin:$PATH"
# on it too. Forward slashes work everywhere.
[ -f local.properties ] || echo "sdk.dir=$(printf '%s' "$ANDROID_HOME" | tr '\\' '/')" > local.properties
./gradlew assembleRelease -q --console=plain
+elif [ ! -f app/build/outputs/apk/release/app-release.apk ]; then
+ echo "ERROR: SKIP_BUILD=1 but there is no app/build/outputs/apk/release/app-release.apk; build it first (tools/docker-build.sh)." >&2
+ exit 1
+fi
# Which app owns Home differs by build (com.google.android.tvlauncher on Android TV,
# com.google.android.apps.tv.launcherx on newer Google TV), so ask the TV instead of guessing.
# Only a launcher we recognise is accepted: the answer can also be Android's chooser ("android"),
diff --git a/tools/docker-build.md b/tools/docker-build.md
new file mode 100644
index 000000000..116b0d67b
--- /dev/null
+++ b/tools/docker-build.md
@@ -0,0 +1,61 @@
+# Building in Docker
+
+`tools/docker-build.sh` (and its twin `tools/docker-build.ps1`) builds the launcher or an add-on inside a container
+that has JDK 17, Android SDK 34 and build-tools 34.0.0. This computer needs Docker and nothing else: no JDK, no
+Android Studio, no `ANDROID_HOME`. The APK is built from this checkout, on this computer, and lands where a native
+build puts it.
+
+## Build
+
+```bash
+tools/docker-build.sh # the launcher (assembleRelease)
+tools/docker-build.sh addons/weather # an add-on
+tools/docker-build.sh launcher testReleaseUnitTest lintRelease assembleRelease # what CI runs
+```
+
+```powershell
+tools\docker-build.ps1
+tools\docker-build.ps1 -Project addons\weather
+tools\docker-build.ps1 -Project launcher -Tasks testReleaseUnitTest,lintRelease,assembleRelease
+```
+
+The first run builds the image from `tools/docker/Dockerfile` (a few minutes, about 1.5 GB) and Gradle downloads its
+distribution into the `cleanyourtv-gradle` volume; later builds reuse both. On Linux and macOS the container runs as
+your user, so the build output is not owned by root.
+
+| Variable | Default | What it changes |
+|---|---|---|
+| `IMAGE` | `cleanyourtv-android-build` | The image name |
+| `GRADLE_VOLUME` | `cleanyourtv-gradle` | The Docker volume that keeps Gradle's caches and the signing key |
+| `KEY_DIR` | `/gradle/.android` | Where the debug signing key is kept inside the container |
+| `HOST_KEY_DIR` | (none) | A folder on this computer to take the key from instead, such as `~/.android` |
+
+## Install
+
+The launcher's install script builds with the JDK on this computer unless told not to. With the APK built in
+Docker:
+
+```bash
+SKIP_BUILD=1 TV_HOST=<tv ip> launcher/build-and-install.sh
+```
+
+```powershell
+$env:SKIP_BUILD = '1'; launcher\build-and-install.ps1 -TvHost <tv ip>
+```
+
+Everything else the script does (the SDK check, the Home guard, the stock launcher) is unchanged. An add-on's APK
+is pushed and installed as [`addons/README.md`](../addons/README.md) shows, without its build step.
+
+## The signing key
+
+The release APK is signed with a debug key, and Android only installs an update signed with the same key as the
+app already on the TV. Docker keeps its key in the Gradle volume, which is a different key from the one a native
+build uses (`~/.android/debug.keystore`). Switching between a Docker build and a native build therefore fails
+with `INSTALL_FAILED_UPDATE_INCOMPATIBLE`.
+
+- Build one app the same way every time, or
+- sign Docker builds with your native key: `HOST_KEY_DIR=~/.android tools/docker-build.sh`, or
+- uninstall the app on the TV once and install the new build (its settings on the TV are lost).
+
+To see which key an installed app carries, compare
+`apksigner verify --print-certs` on the APK with `keytool -list -v -keystore <dir>/debug.keystore -storepass android`.
diff --git a/tools/docker-build.ps1 b/tools/docker-build.ps1
new file mode 100644
index 000000000..22c8ade6e
--- /dev/null
+++ b/tools/docker-build.ps1
@@ -0,0 +1,46 @@
+# Build the launcher or an add-on inside Docker, so this computer needs no JDK or Android SDK.
+# Usage: tools\docker-build.ps1 [-Project launcher | addons\<name>] [-Tasks <gradle task>, ...]
+# tools\docker-build.ps1
+# tools\docker-build.ps1 -Project addons\weather
+# tools\docker-build.ps1 -Project launcher -Tasks testReleaseUnitTest,lintRelease,assembleRelease
+# The APK lands where a native build puts it (<project>\app\build\outputs\apk\release\).
+# Install the launcher with: $env:SKIP_BUILD = '1'; launcher\build-and-install.ps1
+# Guide, signing key included: tools/docker-build.md
+param(
+ [string]$Project = 'launcher',
+ [string[]]$Tasks = @('assembleRelease')
+)
+$ErrorActionPreference = 'Stop'
+$Root = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
+$Project = $Project.TrimEnd('\', '/') -replace '\\', '/'
+$Image = if ($env:IMAGE) { $env:IMAGE } else { 'cleanyourtv-android-build' }
+$Volume = if ($env:GRADLE_VOLUME) { $env:GRADLE_VOLUME } else { 'cleanyourtv-gradle' }
+# Where the debug signing key lives inside the container; see tools/docker-build.md.
+$KeyDir = if ($env:KEY_DIR) { $env:KEY_DIR } else { '/gradle/.android' }
+
+if (-not (Test-Path (Join-Path $Root "$Project/settings.gradle")) -and
+ -not (Test-Path (Join-Path $Root "$Project/settings.gradle.kts"))) {
+ throw "$Project is not a Gradle project in this repository (try launcher or addons/<name>)."
+}
+if (-not (Get-Command docker -ErrorAction SilentlyContinue)) { throw 'docker is not installed or not on PATH.' }
+
+docker image inspect $Image *> $null
+if ($LASTEXITCODE -ne 0) {
+ Write-Host "Building the $Image image once (JDK 17, Android SDK 34, build-tools 34.0.0; a few minutes)..."
+ docker build -t $Image (Join-Path $Root 'tools/docker')
+ if ($LASTEXITCODE -ne 0) { throw 'docker build failed' }
+}
+
+$keyArgs = @()
+if ($env:HOST_KEY_DIR) {
+ $keyArgs = @('-v', "$($env:HOST_KEY_DIR):/key")
+ $KeyDir = '/key'
+}
+
+# The whole repository is mounted: an add-on's gradlew may call ../../launcher/gradlew.
+docker run --rm @keyArgs -v "${Root}:/repo" -v "${Volume}:/gradle" -w "/repo/$Project" `
+ -e "ANDROID_USER_HOME=$KeyDir" $Image sh ./gradlew --no-daemon --console=plain @Tasks
+if ($LASTEXITCODE -ne 0) { throw 'gradle failed in the container' }
+
+Get-ChildItem (Join-Path $Root "$Project/app/build/outputs/apk") -Recurse -Filter *.apk -ErrorAction SilentlyContinue |
+ ForEach-Object { Write-Host "APK: $($_.FullName.Substring($Root.Length + 1)) ($($_.Length) B)" }
diff --git a/tools/docker-build.sh b/tools/docker-build.sh
new file mode 100755
index 000000000..0ecedf25e
--- /dev/null
+++ b/tools/docker-build.sh
@@ -0,0 +1,62 @@
+#!/usr/bin/env bash
+# Build the launcher or an add-on inside Docker, so this computer needs no JDK or Android SDK.
+# Usage: tools/docker-build.sh [launcher | addons/<name>] [gradle task ...]
+# tools/docker-build.sh the launcher, assembleRelease
+# tools/docker-build.sh addons/weather an add-on
+# tools/docker-build.sh launcher testReleaseUnitTest lintRelease assembleRelease
+# The APK lands where a native build puts it (<project>/app/build/outputs/apk/release/).
+# Install the launcher with: SKIP_BUILD=1 TV_HOST=<tv ip> launcher/build-and-install.sh
+# Guide, signing key included: tools/docker-build.md
+set -euo pipefail
+ROOT="$(cd "$(dirname "$0")/.." && pwd)"
+PROJECT="${1:-launcher}"
+[ $# -gt 0 ] && shift
+TASKS=("$@")
+[ ${#TASKS[@]} -gt 0 ] || TASKS=(assembleRelease)
+IMAGE="${IMAGE:-cleanyourtv-android-build}"
+GRADLE_VOLUME="${GRADLE_VOLUME:-cleanyourtv-gradle}"
+# Where the debug signing key lives inside the container. The default is the image's own, kept in the Gradle volume;
+# KEY_DIR picks another place in it, HOST_KEY_DIR mounts a folder from this computer (your ~/.android, say).
+KEY_DIR="${KEY_DIR:-/gradle/.android}"
+
+PROJECT="${PROJECT%/}"
+if [ ! -f "$ROOT/$PROJECT/settings.gradle" ] && [ ! -f "$ROOT/$PROJECT/settings.gradle.kts" ]; then
+ echo "ERROR: $PROJECT is not a Gradle project in this repository (try launcher or addons/<name>)." >&2
+ exit 1
+fi
+command -v docker >/dev/null || { echo "ERROR: docker is not installed or not on PATH." >&2; exit 1; }
+
+if ! docker image inspect "$IMAGE" >/dev/null 2>&1; then
+ echo "Building the $IMAGE image once (JDK 17, Android SDK 34, build-tools 34.0.0; a few minutes)..."
+ docker build -t "$IMAGE" "$ROOT/tools/docker"
+fi
+
+# Git Bash on Windows rewrites /paths in arguments and gives POSIX paths Docker can't mount.
+SRC="$ROOT"
+USER_ARGS=()
+case "$(uname -s)" in
+ MINGW* | MSYS* | CYGWIN*)
+ export MSYS_NO_PATHCONV=1
+ SRC="$(cd "$ROOT" && pwd -W)"
+ ;;
+ *)
+ # The caller's uid, so the build output is not owned by root.
+ USER_ARGS=(--user "$(id -u):$(id -g)")
+ ;;
+esac
+KEY_ARGS=()
+if [ -n "${HOST_KEY_DIR:-}" ]; then
+ KEY_ARGS=(-v "$HOST_KEY_DIR:/key")
+ KEY_DIR=/key
+fi
+
+# The whole repository is mounted: an add-on's gradlew may call ../../launcher/gradlew.
+docker run --rm ${USER_ARGS[@]+"${USER_ARGS[@]}"} ${KEY_ARGS[@]+"${KEY_ARGS[@]}"} \
+ -v "$SRC:/repo" -v "$GRADLE_VOLUME:/gradle" -w "/repo/$PROJECT" \
+ -e ANDROID_USER_HOME="$KEY_DIR" \
+ "$IMAGE" sh ./gradlew --no-daemon --console=plain "${TASKS[@]}"
+
+for apk in "$ROOT/$PROJECT"/app/build/outputs/apk/*/*.apk; do
+ [ -f "$apk" ] && echo "APK: ${apk#"$ROOT"/} ($(wc -c < "$apk" | tr -d ' ') B)"
+done
+exit 0
diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile
new file mode 100644
index 000000000..5339c7772
--- /dev/null
+++ b/tools/docker/Dockerfile
@@ -0,0 +1,49 @@
+# The whole Android toolchain, so the host needs nothing but Docker.
+# Temurin 17 is what Android Gradle Plugin 8 is tested against; the host JDK is never read.
+FROM eclipse-temurin:17-jdk
+
+ARG CMDLINE_TOOLS_VERSION=11076708
+ARG COMPILE_SDK=34
+ARG BUILD_TOOLS=34.0.0
+
+ENV ANDROID_HOME=/opt/android-sdk \
+ ANDROID_SDK_ROOT=/opt/android-sdk \
+ GRADLE_USER_HOME=/gradle \
+ DEBIAN_FRONTEND=noninteractive
+
+RUN apt-get update \
+ && apt-get install -y --no-install-recommends unzip curl make git \
+ && rm -rf /var/lib/apt/lists/*
+
+# sdkmanager insists on living at cmdline-tools/latest, and the zip unpacks to
+# cmdline-tools/, so the move is not cosmetic.
+RUN mkdir -p "$ANDROID_HOME/cmdline-tools" \
+ && curl -fsSL -o /tmp/cmdline-tools.zip \
+ "https://dl.google.com/android/repository/commandlinetools-linux-${CMDLINE_TOOLS_VERSION}_latest.zip" \
+ && unzip -q /tmp/cmdline-tools.zip -d "$ANDROID_HOME/cmdline-tools" \
+ && mv "$ANDROID_HOME/cmdline-tools/cmdline-tools" "$ANDROID_HOME/cmdline-tools/latest" \
+ && rm /tmp/cmdline-tools.zip
+
+ENV PATH="$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$PATH"
+
+# Licences are accepted here so no build ever stops on a prompt.
+RUN yes | sdkmanager --licenses > /dev/null \
+ && sdkmanager --install \
+ "platform-tools" \
+ "platforms;android-${COMPILE_SDK}" \
+ "build-tools;${BUILD_TOOLS}" \
+ && sdkmanager --list_installed
+
+# The Gradle home is a named volume at run time. Making it world-writable here
+# lets the container run as the caller's uid without root-owned files landing
+# in the mounted source tree.
+RUN mkdir -p /gradle && chmod 777 /gradle
+RUN chmod -R a+rX "$ANDROID_HOME"
+
+# Running as the caller's uid means there is no passwd entry and HOME falls back
+# to "/", which is root-owned: the Android Gradle Plugin then dies trying to
+# create /.android. Point both at the writable Gradle volume instead.
+ENV HOME=/gradle \
+ ANDROID_USER_HOME=/gradle/.android
+
+WORKDIR /workspace