Build Android APK / Build Release APKs (push) Successful in 17m46s
Flutter 3.47's gen_snapshot calls pthread_getattr_np(), which crashes the
QEMU 8.2.2 shipped by Ubuntu 24.04 ("QEMU internal SIGSEGV {code=MAPERR,
addr=0x20}", qemu#2170, fixed in 8.2.3/9.0). Install the static qemu-x86_64
from Debian trixie's qemu-user package (sha1-pinned) over the apt binary.
The build steps swallowed non-zero exit codes with an `|| { find ... }`
fallback, so the job turned green without producing any APK. Run the
builds plainly, fail "Organize Artifacts" unless all four APKs exist and
set if-no-files-found: error on the uploads.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
227 lines
9.6 KiB
YAML
227 lines
9.6 KiB
YAML
name: Build Android APK
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- master
|
|
- 'refactor/**'
|
|
tags:
|
|
- 'v*'
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
- master
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
# Keep in sync with .github/workflows/build-ios.yaml and pubspec.yaml (environment).
|
|
FLUTTER_VERSION: '3.47.4'
|
|
# Static qemu-x86_64 for the ARM64 runner (Debian trixie `qemu-user`, see below).
|
|
QEMU_DEB_VERSION: '10.0.13+ds-0+deb13u1'
|
|
QEMU_DEB_SHA1: '02b553a4532192bc999d15408d1e56d7b254906f'
|
|
|
|
jobs:
|
|
build-android:
|
|
name: Build Release APKs
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
container:
|
|
# Cirrus Labs stopped publishing Flutter images in May 2026 (last tag: 3.44.0,
|
|
# multi-arch amd64/arm64, Ubuntu 24.04, OpenJDK 21, Android SDK 36). The image is
|
|
# only used for its JDK + Android SDK; the bundled Flutter SDK is switched to
|
|
# FLUTTER_VERSION in the first step.
|
|
image: ghcr.io/cirruslabs/flutter:3.44.0
|
|
options: --privileged
|
|
steps:
|
|
- name: Switch Flutter SDK to pinned version
|
|
# act_runner defaults to `sh -e` (dash); bash is needed for `pipefail`.
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
FLUTTER_ROOT="${FLUTTER_ROOT:-/sdks/flutter}"
|
|
git config --global --add safe.directory "$FLUTTER_ROOT"
|
|
git config --global --add safe.directory '*'
|
|
CURRENT="$(git -C "$FLUTTER_ROOT" describe --tags --exact-match 2>/dev/null || true)"
|
|
if [ "$CURRENT" != "$FLUTTER_VERSION" ]; then
|
|
echo "Switching Flutter SDK from '${CURRENT:-unknown}' to '$FLUTTER_VERSION'"
|
|
git -C "$FLUTTER_ROOT" fetch --depth 1 origin "refs/tags/${FLUTTER_VERSION}:refs/tags/${FLUTTER_VERSION}"
|
|
git -C "$FLUTTER_ROOT" checkout -q "$FLUTTER_VERSION"
|
|
# Drop the cache of the previous version; the Dart SDK and the engine
|
|
# artifacts for the new version are downloaded on first use.
|
|
rm -rf "$FLUTTER_ROOT/bin/cache"
|
|
fi
|
|
flutter --version
|
|
|
|
- name: Setup Node.js 20 & ARM64 Flutter Engine
|
|
run: |
|
|
ARCH=$(uname -m)
|
|
if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then NODE_ARCH="arm64"; else NODE_ARCH="x64"; fi
|
|
curl -fsSL "https://nodejs.org/dist/v20.18.0/node-v20.18.0-linux-${NODE_ARCH}.tar.gz" | tar -xzf - -C /usr/local --strip-components=1
|
|
node --version
|
|
|
|
# On Linux ARM64, Flutter engine and Android AAPT2 need x86_64 emulation via QEMU.
|
|
if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
|
|
echo "Setting up ARM64 Flutter environment & QEMU binfmt emulation..."
|
|
apt-get update -qq && apt-get install -y -qq qemu-user-static binfmt-support libc6-amd64-cross libstdc++6-amd64-cross gcc
|
|
|
|
# Setup x86_64 dynamic libraries & prefix for QEMU emulation
|
|
mkdir -p /etc/qemu-binfmt
|
|
ln -sf /usr/x86_64-linux-gnu /etc/qemu-binfmt/x86_64
|
|
mkdir -p /lib64 /usr/lib64
|
|
ln -sf /usr/x86_64-linux-gnu/lib/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2
|
|
ln -sf /usr/x86_64-linux-gnu/lib/* /lib64/ 2>/dev/null || true
|
|
ln -sf /usr/x86_64-linux-gnu/lib/* /usr/lib64/ 2>/dev/null || true
|
|
|
|
export QEMU_LD_PREFIX=/usr/x86_64-linux-gnu
|
|
echo "QEMU_LD_PREFIX=/usr/x86_64-linux-gnu" >> "$GITHUB_ENV"
|
|
|
|
# Ubuntu 24.04 ships QEMU 8.2.2, whose x86_64 user-mode emulation dies with
|
|
# "QEMU internal SIGSEGV {code=MAPERR, addr=0x20}" as soon as the guest calls
|
|
# pthread_getattr_np() - which Dart's gen_snapshot does since Flutter 3.4x
|
|
# (https://gitlab.com/qemu-project/qemu/-/issues/2170, fixed in 8.2.3/9.0).
|
|
# Replace it with the static binary from Debian trixie's qemu-user package.
|
|
QEMU_DEB="qemu-user_${QEMU_DEB_VERSION}_arm64.deb"
|
|
curl -fsSL -o /tmp/qemu-user.deb "https://deb.debian.org/debian/pool/main/q/qemu/${QEMU_DEB}" ||
|
|
curl -fsSL -o /tmp/qemu-user.deb "https://snapshot.debian.org/file/${QEMU_DEB_SHA1}"
|
|
echo "${QEMU_DEB_SHA1} /tmp/qemu-user.deb" | sha1sum -c -
|
|
dpkg-deb -x /tmp/qemu-user.deb /tmp/qemu-user
|
|
install -m 0755 /tmp/qemu-user/usr/bin/qemu-x86_64 /usr/bin/qemu-x86_64-static
|
|
rm -rf /tmp/qemu-user /tmp/qemu-user.deb
|
|
/usr/bin/qemu-x86_64-static --version | head -n 1
|
|
|
|
# Must match the path hard-coded in scripts/ci/qemu_intercept.c.
|
|
QEMU_BIN=/usr/bin/qemu-x86_64-static
|
|
|
|
# Dummy fallbacks for FEX binaries/sockets
|
|
for fex in /usr/bin/FEXInterpreter /usr/bin/FEX /usr/local/bin/FEXInterpreter /usr/bin/FEXServer /usr/local/bin/FEXServer; do
|
|
printf '#!/bin/sh\nexit 0\n' > "$fex"
|
|
chmod +x "$fex" 2>/dev/null || true
|
|
done
|
|
|
|
flutter precache --android
|
|
# Flutter (still) only ships an x86_64 gen_snapshot for Linux hosts; wrap it
|
|
# with QEMU under the linux-arm64 path the tool expects.
|
|
for dir in "${FLUTTER_ROOT:-/sdks/flutter}"/bin/cache/artifacts/engine/android-*; do
|
|
if [ -d "$dir/linux-x64" ] && [ ! -x "$dir/linux-arm64/gen_snapshot" ]; then
|
|
mkdir -p "$dir/linux-arm64"
|
|
printf '#!/bin/sh\nSCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"\nexec env -u LD_PRELOAD %s -L /usr/x86_64-linux-gnu "$SCRIPT_DIR/../linux-x64/gen_snapshot" "$@"\n' "$QEMU_BIN" > "$dir/linux-arm64/gen_snapshot"
|
|
chmod +x "$dir/linux-arm64/gen_snapshot"
|
|
echo "Configured gen_snapshot wrapper for $(basename "$dir")"
|
|
fi
|
|
done
|
|
fi
|
|
|
|
- name: Checkout Repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup QEMU Interceptor
|
|
run: |
|
|
ARCH=$(uname -m)
|
|
if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
|
|
echo "Compiling transparent QEMU execution interceptor..."
|
|
gcc -O2 -shared -fPIC -o /usr/local/lib/libqemu_intercept.so scripts/ci/qemu_intercept.c -ldl
|
|
echo "LD_PRELOAD=/usr/local/lib/libqemu_intercept.so" >> "$GITHUB_ENV"
|
|
rm -f /etc/ld.so.preload
|
|
echo "Enabled LD_PRELOAD interceptor via GITHUB_ENV"
|
|
fi
|
|
|
|
- name: Make Gradlew Executable
|
|
run: |
|
|
if [ -f android/gradlew ]; then
|
|
chmod +x android/gradlew
|
|
fi
|
|
|
|
- name: Inspect Build Environment
|
|
run: |
|
|
flutter --version
|
|
java -version
|
|
node --version
|
|
|
|
- name: Fetch Flutter Dependencies
|
|
run: flutter pub get
|
|
|
|
- name: Run Code Analysis & Tests
|
|
run: |
|
|
flutter analyze
|
|
flutter test
|
|
|
|
- name: Build Universal Release APK
|
|
run: flutter build apk --release
|
|
|
|
- name: Build Split-per-ABI Release APKs
|
|
run: flutter build apk --release --split-per-abi
|
|
|
|
- name: Organize Artifacts
|
|
run: |
|
|
mkdir -p release-apks
|
|
# Copy universal APK
|
|
if [ -f build/app/outputs/flutter-apk/app-release.apk ]; then
|
|
cp build/app/outputs/flutter-apk/app-release.apk release-apks/oggauer-gemeindetrommler-universal.apk
|
|
elif [ -f android/app/build/outputs/apk/release/app-release.apk ]; then
|
|
cp android/app/build/outputs/apk/release/app-release.apk release-apks/oggauer-gemeindetrommler-universal.apk
|
|
fi
|
|
# Copy split APKs
|
|
for apk in build/app/outputs/flutter-apk/*.apk android/app/build/outputs/apk/release/*.apk; do
|
|
[ -f "$apk" ] || continue
|
|
case "$(basename "$apk")" in
|
|
*arm64-v8a*) cp "$apk" release-apks/oggauer-gemeindetrommler-arm64-v8a.apk ;;
|
|
*armeabi-v7a*) cp "$apk" release-apks/oggauer-gemeindetrommler-armeabi-v7a.apk ;;
|
|
*x86_64*) cp "$apk" release-apks/oggauer-gemeindetrommler-x86_64.apk ;;
|
|
esac
|
|
done
|
|
echo "=== Generated APK Artifacts ==="
|
|
ls -lah release-apks/
|
|
if [ "$(ls release-apks/*.apk 2>/dev/null | wc -l)" -ne 4 ]; then
|
|
echo "::error::Expected 4 APKs in release-apks/, the build did not produce all artifacts"
|
|
exit 1
|
|
fi
|
|
|
|
- name: Upload Universal APK
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: oggauer-gemeindetrommler-universal
|
|
path: release-apks/oggauer-gemeindetrommler-universal.apk
|
|
retention-days: 7
|
|
if-no-files-found: error
|
|
|
|
- name: Upload ARM64 APK
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: oggauer-gemeindetrommler-arm64-v8a
|
|
path: release-apks/oggauer-gemeindetrommler-arm64-v8a.apk
|
|
retention-days: 7
|
|
if-no-files-found: error
|
|
|
|
- name: Upload ARMv7 APK
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: oggauer-gemeindetrommler-armeabi-v7a
|
|
path: release-apks/oggauer-gemeindetrommler-armeabi-v7a.apk
|
|
retention-days: 7
|
|
if-no-files-found: error
|
|
|
|
- name: Upload x86_64 APK
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: oggauer-gemeindetrommler-x86_64
|
|
path: release-apks/oggauer-gemeindetrommler-x86_64.apk
|
|
retention-days: 7
|
|
if-no-files-found: error
|
|
|
|
- name: Publish Direct APKs to Gitea Releases
|
|
continue-on-error: true
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
GITEA_API: ${{ github.api_url }}
|
|
REPO: ${{ github.repository }}
|
|
RELEASE_TAG: latest
|
|
run: |
|
|
node scripts/ci/publish_release.js
|
|
|
|
- name: Clean Workspace Disk Space
|
|
if: always()
|
|
run: |
|
|
rm -rf build android/.gradle release-apks 2>/dev/null || true
|