Skip to content

Instantly share code, notes, and snippets.

@derezzolution
Created May 24, 2026 03:56
Show Gist options
  • Select an option

  • Save derezzolution/58ba6b4ff3e791f2fc555e9f27458d70 to your computer and use it in GitHub Desktop.

Select an option

Save derezzolution/58ba6b4ff3e791f2fc555e9f27458d70 to your computer and use it in GitHub Desktop.
Building Android APKs on arm64 (Raspberry Pi) with Gitea Actions and rootless Podman — including the aapt2 x86_64 workaround

Building Android APKs on a Raspberry Pi with Gitea Actions and rootless Podman

A working pattern for self-hosted Android CI on arm64 hardware. This setup builds release APKs for Pixel-class devices without an emulator, runs entirely in rootless Podman under a Quadlet-managed systemd user unit, and works around the fact that Google still ships an x86_64-only aapt2 binary in the Android SDK build-tools.

Tested on a Raspberry Pi 5 (16 GB, NVMe) running Debian 13 trixie, with Gitea 1.24+ and gitea-runner 1.0.x. The pattern should generalize to any arm64 Linux host running rootless Podman.

The problem

Self-hosting Android CI on arm64 hardware sounds simple — install the SDK, run Gradle, profit. In practice there are several non-obvious obstacles:

  1. The Gitea Actions runner project renamed. What was gitea/act_runner is now gitea/runner as of 2026. Old documentation references the previous name and old image tags.
  2. JavaScript-based Actions require Node.js inside the runner container. In "host execution mode" (the right mode for this use case), there is no fallback container that provides Node automatically.
  3. The runner needs explicit configuration to skip Docker. Without it, the daemon exits on startup looking for a Docker socket.
  4. Google's Android SDK build-tools 36 ships aapt2 as an x86_64-only ELF. Even in the "linux" distribution. Confirmed in build-tools 36.0.0; almost certainly true in earlier versions too. There is no linux-arm64 variant from Google.
  5. The standard fix for x86_64-on-arm64 (qemu-user-static + binfmt_misc with the F flag) does not reliably work in rootless Podman. Even with the registration properly set up on the host and the static qemu binary present inside the container, the kernel does not transparently route x86_64 binaries through qemu inside the rootless namespace.

This article documents a working setup that addresses all of these.

Architecture

The runner is a single container image:

  • Base: debian:trixie-slim
  • Runtime: OpenJDK 21, Node.js 20
  • Android SDK: cmdline-tools (latest), platform-tools, platform android-36, build-tools 36.0.0
  • Emulation: qemu-user-static + amd64 multiarch libs (libc6, libstdc++6, zlib1g) for running x86_64 SDK binaries
  • Runner: gitea-runner v1.0.x, host execution mode

The image is managed by a Podman Quadlet unit running under a dedicated podman user with loginctl enable-linger, so the runner survives logouts and reboots.

Persistent state lives in two volumes under ~/.local/share/gitea-runner-android/:

  • data/ — runner config and credentials (config.yaml, .runner)
  • workspace/ — Gradle cache, build outputs

Containerfile

FROM docker.io/debian:trixie-slim

ARG GITEA_RUNNER_VERSION=1.0.6
ARG ANDROID_CMDLINE_TOOLS_BUILD=14742923
ARG ANDROID_PLATFORM=android-36
ARG ANDROID_BUILD_TOOLS=36.0.0

ENV ANDROID_HOME=/opt/android-sdk \
    ANDROID_SDK_ROOT=/opt/android-sdk \
    PATH=/opt/android-sdk/cmdline-tools/latest/bin:/opt/android-sdk/platform-tools:/opt/android-sdk/build-tools/${ANDROID_BUILD_TOOLS}:/usr/local/bin:$PATH \
    JAVA_HOME=/usr/lib/jvm/java-21-openjdk-arm64 \
    GRADLE_USER_HOME=/workspace/.gradle \
    DEBIAN_FRONTEND=noninteractive

# Base packages. Notes:
#   - nodejs is required by JavaScript-based Gitea/GitHub Actions
#     (actions/checkout, actions/cache, etc.) in host execution mode.
#   - qemu-user-static + amd64 multiarch libs are required because
#     Google ships aapt2 as an x86_64-only ELF in the "linux" SDK.
RUN dpkg --add-architecture amd64 && \
    apt-get update && apt-get install -y --no-install-recommends \
        openjdk-21-jdk-headless \
        ca-certificates curl unzip git tini \
        nodejs \
        qemu-user-static \
        libc6:amd64 libstdc++6:amd64 zlib1g:amd64 \
    && rm -rf /var/lib/apt/lists/* \
    && rm -f /usr/bin/qemu-x86_64-static \
    && cp /usr/bin/qemu-x86_64 /usr/bin/qemu-x86_64-static

# Gitea Runner binary (renamed from "act_runner" in 2026)
RUN curl -fsSL --max-time 300 -o /usr/local/bin/gitea-runner \
        "https://gitea.com/gitea/runner/releases/download/v${GITEA_RUNNER_VERSION}/gitea-runner-${GITEA_RUNNER_VERSION}-linux-arm64" \
    && chmod +x /usr/local/bin/gitea-runner

# Android cmdline-tools. Scrape developer.android.com for the current
# build number; fall back to a pinned ARG if the scrape fails.
RUN set -eux; \
    mkdir -p ${ANDROID_HOME}/cmdline-tools; \
    TOOLS_URL=$(curl -fsSL --max-time 30 https://developer.android.com/studio 2>/dev/null \
        | grep -oE 'https://dl\.google\.com/android/repository/commandlinetools-linux-[0-9]+_latest\.zip' \
        | head -n1 || true); \
    if [ -z "${TOOLS_URL}" ]; then \
        TOOLS_URL="https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_CMDLINE_TOOLS_BUILD}_latest.zip"; \
    fi; \
    curl -fsSL --max-time 300 -o /tmp/tools.zip "${TOOLS_URL}"; \
    unzip -q /tmp/tools.zip -d ${ANDROID_HOME}/cmdline-tools; \
    mv ${ANDROID_HOME}/cmdline-tools/cmdline-tools ${ANDROID_HOME}/cmdline-tools/latest; \
    rm /tmp/tools.zip

# Install SDK packages
RUN yes | sdkmanager --licenses >/dev/null && \
    sdkmanager --install \
        "platform-tools" \
        "platforms;${ANDROID_PLATFORM}" \
        "build-tools;${ANDROID_BUILD_TOOLS}" && \
    chmod -R a+rX ${ANDROID_HOME}

# Wrap aapt2 to invoke qemu explicitly. See "The aapt2 problem" below.
RUN mv /opt/android-sdk/build-tools/${ANDROID_BUILD_TOOLS}/aapt2 \
       /opt/android-sdk/build-tools/${ANDROID_BUILD_TOOLS}/aapt2.x86_64 && \
    printf '#!/bin/sh\nexec /usr/bin/qemu-x86_64-static /opt/android-sdk/build-tools/%s/aapt2.x86_64 "$@"\n' \
       "${ANDROID_BUILD_TOOLS}" \
       > /opt/android-sdk/build-tools/${ANDROID_BUILD_TOOLS}/aapt2 && \
    chmod +x /opt/android-sdk/build-tools/${ANDROID_BUILD_TOOLS}/aapt2

WORKDIR /data
ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/gitea-runner"]
CMD ["daemon", "--config", "/data/config.yaml"]

The aapt2 problem in detail

This is the part that took the longest to solve, and the part with the worst documentation elsewhere on the internet.

What goes wrong

Building any Android app that depends on AndroidX (so, virtually all of them) fails during :app:processReleaseResources with stack traces containing:

AAPT2 aapt2-9.1.1-NNNNNNNN-linux Daemon #0: Unexpected error output:
/path/to/aapt2: 1: Syntax error: ")" unexpected

The error message is misleading. aapt2 is not a shell script. The kernel cannot recognize the binary format (an x86_64 ELF on an arm64 host) and falls back to invoking /bin/sh, which then parses the ELF as text and chokes on the first apparent paren.

Confirmed by inspecting the binary:

ELF>...
/lib64/ld-linux-x86-64.so.2

The /lib64/ld-linux-x86-64.so.2 reference in the dynamic linker is the key indicator: this is an x86_64 ELF expecting an x86_64 dynamic loader.

Why the obvious fix fails in rootless Podman

The textbook solution for running foreign-architecture ELFs on Linux is binfmt_misc plus qemu-user-static. Register the binfmt with the F flag, which is supposed to capture the qemu interpreter's file descriptor at registration time so it works inside chroots, containers, and other mount namespaces.

In rootless Podman, this empirically does not work, at least as of mid-2026. Tested configurations that all failed:

  • Default Debian package registration (/usr/libexec/qemu-binfmt/x86_64-binfmt-P dynamic wrapper) → not reachable from container namespace
  • Re-registered pointing to /usr/bin/qemu-x86_64-static (statically linked) → still fails
  • Bind-mounted /proc/sys/fs/binfmt_misc from host into container read-only → registration visible in container, exec still fails
  • Same as above with the static qemu binary present in the container's filesystem at the expected path → still fails

The empirical test that does work: invoke qemu explicitly.

$ /usr/bin/qemu-x86_64-static /opt/android-sdk/build-tools/36.0.0/aapt2 version
Android Asset Packaging Tool (aapt) 2.20-13193326

The static binary, the amd64 multiarch libs, and qemu itself all function correctly. The kernel's binfmt_misc layer is the broken link, specifically in rootless Podman's user/mount namespace setup.

The wrapper script approach

Sidestep binfmt_misc entirely. Move the real aapt2 to aapt2.x86_64 and replace the original name with a two-line shell wrapper:

#!/bin/sh
exec /usr/bin/qemu-x86_64-static /opt/android-sdk/build-tools/36.0.0/aapt2.x86_64 "$@"

This is the last RUN in the Containerfile above. It's crude but it works, requires no host-level setup, and adds approximately 1 millisecond of overhead per aapt2 invocation. For a typical Android app, aapt2 runs 10–20 times per build. Negligible compared to the rest of the build.

Other binaries that might need the same treatment

aapt2 is the most common offender because it runs early and often. Other x86_64-only binaries in the SDK that might need the same wrapper pattern:

  • apksigner
  • zipalign
  • dexdump
  • bcc_compat
  • llvm-rs-cc

If a future build fails with Exec format error on any of these, apply the same wrapper pattern. The pattern has five substitution points (rename source, rename destination, printf template, redirect target, chmod target).

To audit proactively, run a non-privileged container and inspect:

podman run --rm -it --entrypoint /bin/bash localhost/gitea-runner-android:latest
# Inside the container:
apt-get update && apt-get install -y file
for f in /opt/android-sdk/build-tools/36.0.0/*; do
    [ -f "$f" ] && [ -x "$f" ] && file "$f" | grep -q 'x86-64' && echo "$f"
done

Quadlet unit

~/.config/containers/systemd/gitea-runner-android.container:

[Unit]
Description=Gitea Runner for Android arm64 builds
After=network-online.target
Wants=network-online.target

[Container]
Image=localhost/gitea-runner-android:latest
ContainerName=gitea-runner-android
AutoUpdate=local

Volume=%h/.local/share/gitea-runner-android/data:/data:Z
Volume=%h/.local/share/gitea-runner-android/workspace:/workspace:Z

Environment=TZ=America/Los_Angeles
Environment=GRADLE_OPTS=-Dorg.gradle.daemon=false -Dorg.gradle.workers.max=2 -Xmx3g

[Service]
Restart=on-failure
RestartSec=15

[Install]
WantedBy=default.target

The GRADLE_OPTS settings are conservative for a 16 GB Pi shared with other services. Increase -Xmx if builds OOM during R8 minification.

The container reads everything it needs from /data/config.yaml. Note that gitea-runner 1.0.x does not read environment variables like GITEA_INSTANCE_URL or GITEA_RUNNER_REGISTRATION_TOKEN_FILE — those were features of third-party wrapper entrypoints, not the upstream binary. All settings live in the YAML config.

Initial setup

# 1. Build the image
cd ~/gitea-runner-android
podman build -t localhost/gitea-runner-android:latest .

# 2. Create persistent directories
mkdir -p ~/.local/share/gitea-runner-android/{data,workspace}
mkdir -p ~/.config/containers/systemd/

# 3. Generate default config.yaml
podman run --rm \
    -v ~/.local/share/gitea-runner-android/data:/data:Z \
    --entrypoint /usr/local/bin/gitea-runner \
    localhost/gitea-runner-android:latest \
    generate-config > ~/.local/share/gitea-runner-android/data/config.yaml

Edit the generated config.yaml to make two required changes:

runner:
  labels:
    - "android-arm64:host"
    - "android:host"

container:
  docker_host: "-"

The :host label suffix tells gitea-runner to execute jobs directly in the runner container instead of spawning a child container per job — which is what we want, since the runner image is the build environment. The docker_host: "-" disables the Docker socket lookup that would otherwise fail.

Register the runner with Gitea:

TOKEN='paste-registration-token-from-gitea-here'

podman run --rm \
    -v ~/.local/share/gitea-runner-android/data:/data:Z \
    -w /data \
    --entrypoint /usr/local/bin/gitea-runner \
    localhost/gitea-runner-android:latest \
    register --no-interactive \
        --instance https://gitea.example.com \
        --token "${TOKEN}" \
        --name raspi-runner-android \
        --config /data/config.yaml

Registration writes a .runner credential file to /data/. The original token is consumed and can be deleted.

Install and start the Quadlet unit:

cp gitea-runner-android.container ~/.config/containers/systemd/
loginctl enable-linger $USER
systemctl --user daemon-reload
systemctl --user start gitea-runner-android.service

The runner should appear in the Gitea admin/runners page as idle within a few seconds.

Example workflow

.gitea/workflows/build.yml in any Android repo:

name: Build APK

on:
  push:
    branches: [main]
  pull_request:
  workflow_dispatch:

jobs:
  build:
    runs-on: android-arm64
    steps:
      - uses: actions/checkout@v4

      - name: Cache Gradle dependencies
        uses: actions/cache@v4
        with:
          path: |
            ~/.gradle/caches
            ~/.gradle/wrapper
          key: gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}

      - name: Build release APK (arm64-v8a only)
        run: ./gradlew assembleRelease -Pandroid.injected.build.abi=arm64-v8a

      - uses: https://github.com/christopherHX/gitea-upload-artifact@v4
        with:
          name: app-release
          path: app/build/**/release/*.apk
          retention-days: 30

Two notes on the upload-artifact action:

  • actions/upload-artifact@v3 is deprecated upstream, and @v4 aborts on Gitea because it detects the instance as GitHub Enterprise Server. The christopherHX/gitea-upload-artifact@v4 fork strips that check and is the standard Gitea-compatible option.
  • The ** glob in the artifact path is intentional. AGP 9.x places debug-signed release APKs at app/build/intermediates/apk/release/ rather than the historical app/build/outputs/apk/release/. AGP treats debug-signed builds as test-only and stages them in intermediates/. The glob handles both paths.

Sideloading APKs

A consequence of building debug-signed release APKs: the resulting APK is marked android:testOnly="true" in the manifest, and adb install refuses it without the -t flag:

$ adb install app-release.apk
adb: failed to install app-release.apk: Failure [INSTALL_FAILED_TEST_ONLY]

$ adb install -t app-release.apk
Success

For real distribution (Play Store, signed release builds for non-developer devices), set up a proper signingConfigs.create("release") { ... } block reading a keystore from Gitea repo secrets. Out of scope for this article.

Maintenance

Four pinned versions in the Containerfile (GITEA_RUNNER_VERSION, ANDROID_CMDLINE_TOOLS_BUILD, ANDROID_PLATFORM, ANDROID_BUILD_TOOLS). Bump as needed:

Pin Source
GITEA_RUNNER_VERSION https://gitea.com/gitea/runner/releases
ANDROID_CMDLINE_TOOLS_BUILD https://developer.android.com/studio ("Command line tools only" section)
ANDROID_PLATFORM https://developer.android.com/tools/releases/platforms
ANDROID_BUILD_TOOLS https://developer.android.com/tools/releases/build-tools

After bumping, rebuild and restart:

podman build -t localhost/gitea-runner-android:latest .
systemctl --user restart gitea-runner-android

The .runner credentials file persists across image rebuilds; no re-registration needed.

Performance notes

On a Raspberry Pi 5 with NVMe storage and 16 GB RAM:

  • Cold build of a minimal Java Android app: roughly 90 seconds (most of it Gradle distribution download + dependency resolution)
  • Warm build (cached Gradle + dependencies): roughly 45 seconds
  • Image build from scratch: roughly 5 minutes (most of it the JDK + Android SDK downloads)

The qemu overhead on aapt2 is invisible in practice. Gradle, javac, and the dex tools are arm64-native and run at full speed.

Summary

The combination that works:

  1. Debian 13 trixie-slim base with amd64 multiarch enabled and amd64 versions of glibc / libstdc++ / zlib installed alongside arm64 ones
  2. qemu-user-static installed inside the container, real binary at /usr/bin/qemu-x86_64-static (replacing Debian's default symlink to qemu-x86_64)
  3. Shell wrapper around aapt2 (and any other x86_64-only SDK binary) that explicitly invokes qemu
  4. gitea-runner 1.0.x in host mode with explicit docker_host: "-" and labels in config.yaml
  5. Quadlet-managed user systemd unit with lingering enabled

The setup has been running reliably on a Pi 5 building real Android apps. The wrapper-script approach is the load-bearing piece — it avoids the binfmt_misc / rootless Podman incompatibility that defeats every cleaner solution.

If you find additional x86_64 SDK binaries that need the same treatment, the wrapper pattern is mechanical. Audit periodically; Google's arm64 support in build-tools may eventually improve and obviate this whole approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment