Skip to content

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

tools: docker-build builds and runs the image as x86-64, so an Apple Silicon Mac gets an APK (#2941)

Gathin233cacdd57c784
diff --git a/tests/test_docker_build_first_run.py b/tests/test_docker_build_first_run.py
index ef715778d..408fa19b5 100644
--- a/tests/test_docker_build_first_run.py
+++ b/tests/test_docker_build_first_run.py
@@ -158,7 +158,7 @@ class PowerShellFirstRunTest(unittest.TestCase):
done, calls = run_with_stub(["-File", str(PS1)], PWSH)
self.assertEqual(0, done.returncode, done.stdout + done.stderr)
self.assertEqual(["image", "inspect", IMAGE], calls[0])
- self.assertEqual(["build", "-t", IMAGE, str(DOCKERFILE_DIR)], calls[1],
+ self.assertEqual(["build", "--platform", "linux/amd64", "-t", IMAGE, str(DOCKERFILE_DIR)], calls[1],
"the build #2890 never reached")
self.assertEqual("run", calls[2][0], calls)
self.assertIn("/repo/launcher", calls[2])
@@ -185,7 +185,27 @@ class ShellTwinTest(unittest.TestCase):
done, calls = run_with_stub([str(SH)], BASH)
self.assertEqual(0, done.returncode, done.stdout + done.stderr)
self.assertEqual(["image", "inspect", IMAGE], calls[0])
- self.assertEqual(["build", "-t", IMAGE, str(DOCKERFILE_DIR)], calls[1])
+ self.assertEqual(["build", "--platform", "linux/amd64", "-t", IMAGE, str(DOCKERFILE_DIR)], calls[1])
+
+ def test_the_shell_twin_runs_the_build_as_x86_64(self):
+ # #2941: the Linux AAPT2 is x86-64 only, so an arm64 container fails at mergeReleaseResources.
+ done, calls = run_with_stub([str(SH)], BASH, state="present")
+ self.assertEqual(0, done.returncode, done.stdout + done.stderr)
+ run = calls[1]
+ self.assertEqual("run", run[0], calls)
+ self.assertIn("--platform", run)
+ self.assertEqual("linux/amd64", run[run.index("--platform") + 1])
+
+
+class PlatformPinTest(unittest.TestCase):
+ """#2941: both twins build and run the image as x86-64, whatever the host is (a source check, so it runs
+ without pwsh too)."""
+
+ def test_the_powershell_twin_builds_and_runs_as_x86_64(self):
+ text = PS1.read_text(encoding="utf-8")
+ self.assertIn("$Platform = 'linux/amd64'", text)
+ self.assertIn("docker build --platform $Platform -t $Image", text)
+ self.assertIn("docker run --rm --platform $Platform", text)
if __name__ == "__main__":
diff --git a/tools/docker-build.md b/tools/docker-build.md
index 15faa6d9f..407291a95 100644
--- a/tools/docker-build.md
+++ b/tools/docker-build.md
@@ -30,13 +30,23 @@ your user, so the build output is not owned by root.
| `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` |
-## On an Apple Silicon Mac
+## On an Apple Silicon Mac or another ARM computer
-The build fails there in an arm64 Docker VM (Colima on an M-series Mac): `:app:mergeReleaseResources` stops with
-`AAPT2 aapt2-8.5.2-11315950-linux Daemon #0: Daemon startup failed`, because the Linux AAPT2 that the Android Gradle
-plugin downloads is built for x86-64 and the container is arm64. Build natively instead: Homebrew's `openjdk@17`
-and an Android SDK with platform 34 and build-tools 34.0.0, which the install script below finds on its own when
-run without `SKIP_BUILD`. Running the container as x86-64 under emulation was not tried.
+The Linux AAPT2 that the Android Gradle plugin downloads is built for x86-64 only, so both scripts build and run
+the image as `linux/amd64` whatever the computer is; Docker Desktop runs it under Rosetta (turn on "Use Rosetta for
+x86_64/amd64 emulation" in its settings) or QEMU, and Colima needs
+`colima start --vm-type vz --vz-rosetta`. On an M-series Mac the first build took about 7 minutes and
+later ones well under a minute ([#2941](https://github.com/Gathin23/cleanyourtv/issues/2941)). Before this, an
+arm64 image stopped at `:app:mergeReleaseResources` with `AAPT2 aapt2-8.5.2-11315950-linux Daemon #0: Daemon
+startup failed` or `rosetta error: failed to open elf at /lib64/ld-linux-x86-64.so.2`. If an older copy of the
+script left that arm64 image behind, remove it once so the next run builds the right one:
+
+```bash
+docker image rm cleanyourtv-android-build
+```
+
+A native build works on these computers too: Homebrew's `openjdk@17` and an Android SDK with platform 34 and
+build-tools 34.0.0, which the install script below finds on its own when run without `SKIP_BUILD`.
## Install
diff --git a/tools/docker-build.ps1 b/tools/docker-build.ps1
index 6d0df8b77..4e7e55dde 100644
--- a/tools/docker-build.ps1
+++ b/tools/docker-build.ps1
@@ -43,18 +43,21 @@ if ($env:HOST_KEY_DIR) {
# it: on a first run the image does not exist yet, so this probe writes "No such image" to stderr - the case
# the line below is there to handle - and the build is never reached. Ask docker with 'Continue' and judge
# the exit code.
+# Always x86-64, as in the shell twin: the Linux AAPT2 the Android Gradle plugin downloads is x86-64 only, so an
+# arm64 image (Windows on ARM) stops at :app:mergeReleaseResources (#2941). On an x86-64 computer it changes nothing.
+$Platform = 'linux/amd64'
$ErrorActionPreference = 'Continue'
docker image inspect $Image *> $null
$Missing = $LASTEXITCODE -ne 0
$ErrorActionPreference = 'Stop'
if ($Missing) {
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')
+ docker build --platform $Platform -t $Image (Join-Path $Root 'tools/docker')
if ($LASTEXITCODE -ne 0) { throw 'docker build failed' }
}
# 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" `
+docker run --rm --platform $Platform @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' }
diff --git a/tools/docker-build.sh b/tools/docker-build.sh
index ea96442fe..24f1602a9 100755
--- a/tools/docker-build.sh
+++ b/tools/docker-build.sh
@@ -54,9 +54,13 @@ if [ -n "${HOST_KEY_DIR:-}" ]; then
KEY_DIR=/key
fi
+# Always x86-64, on an Apple Silicon Mac or an ARM board too: the Linux AAPT2 the Android Gradle plugin downloads
+# is published for x86-64 only, so an arm64 image stops at :app:mergeReleaseResources minutes in (#2941). Docker
+# Desktop runs it under Rosetta or QEMU; on an x86-64 computer the flag changes nothing.
+PLATFORM=linux/amd64
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"
+ docker build --platform "$PLATFORM" -t "$IMAGE" "$ROOT/tools/docker"
fi
# Git Bash on Windows rewrites /paths in arguments and gives POSIX paths Docker can't mount.
@@ -73,7 +77,7 @@ case "$(uname -s)" in
;;
esac
# 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[@]}"} \
+docker run --rm --platform "$PLATFORM" ${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[@]}"