275 lines
12 KiB
YAML
275 lines
12 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
|
|
timeout-minutes: 180
|
|
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 llvm
|
|
|
|
# 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
|
|
|
|
# AGP strips libflutter.so/libapp.so with the NDK's llvm-strip; unstripped they
|
|
# are ~15x larger (165 MB instead of 12 MB per ABI). The NDK's x86_64 llvm-strip
|
|
# cannot run under QEMU (needs libz.so.1 etc. in the cross sysroot), so install
|
|
# the NDK Flutter expects up front and swap in Ubuntu's native arm64 llvm-strip.
|
|
NDK_VERSION="$(sed -nE 's/.*ndkVersion: String = "([^"]+)".*/\1/p' "${FLUTTER_ROOT:-/sdks/flutter}/packages/flutter_tools/gradle/src/main/kotlin/FlutterExtension.kt")"
|
|
[ -n "$NDK_VERSION" ] || { echo "::error::Could not determine Flutter's NDK version"; exit 1; }
|
|
echo "Installing NDK $NDK_VERSION and Android SDK platforms 34 & 35 ..."
|
|
yes | sdkmanager --install "platforms;android-34" "platforms;android-35" "ndk;${NDK_VERSION}" > /dev/null
|
|
NDK_BIN="${ANDROID_HOME:-/opt/android-sdk-linux}/ndk/${NDK_VERSION}/toolchains/llvm/prebuilt/linux-x86_64/bin"
|
|
for tool in llvm-strip llvm-objcopy; do
|
|
mv "$NDK_BIN/$tool" "$NDK_BIN/$tool.x86_64"
|
|
ln -s "$(command -v "$tool")" "$NDK_BIN/$tool"
|
|
done
|
|
"$NDK_BIN/llvm-strip" --version | head -n 2
|
|
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 Release APKs (Split-per-ABI & Universal)
|
|
run: |
|
|
flutter build apk --release --split-per-abi
|
|
mkdir -p release-apks
|
|
# Locate universal APK generated by AGP splits
|
|
for f in \
|
|
build/app/outputs/flutter-apk/app-universal-release.apk \
|
|
build/app/outputs/flutter-apk/*universal*.apk \
|
|
android/app/build/outputs/apk/release/app-universal-release.apk \
|
|
android/app/build/outputs/apk/release/*universal*.apk \
|
|
build/app/outputs/flutter-apk/app-release.apk \
|
|
android/app/build/outputs/apk/release/app-release.apk; do
|
|
if [ -f "$f" ]; then
|
|
echo "Found universal APK at $f"
|
|
cp "$f" release-apks/oggauer-gemeindetrommler-universal.apk
|
|
break
|
|
fi
|
|
done
|
|
# Fallback: if universal APK was not created by split build, build it explicitly
|
|
if [ ! -f release-apks/oggauer-gemeindetrommler-universal.apk ]; then
|
|
echo "Universal APK not found from split build; running fallback universal build..."
|
|
flutter build apk --release
|
|
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
|
|
fi
|
|
|
|
- name: Organize Artifacts
|
|
run: |
|
|
mkdir -p release-apks
|
|
# Copy universal APK if not already in release-apks
|
|
if [ ! -f release-apks/oggauer-gemeindetrommler-universal.apk ]; then
|
|
for f in \
|
|
build/app/outputs/flutter-apk/app-universal-release.apk \
|
|
build/app/outputs/flutter-apk/*universal*.apk \
|
|
android/app/build/outputs/apk/release/app-universal-release.apk \
|
|
android/app/build/outputs/apk/release/*universal*.apk \
|
|
build/app/outputs/flutter-apk/app-release.apk \
|
|
android/app/build/outputs/apk/release/app-release.apk; do
|
|
if [ -f "$f" ]; then
|
|
cp "$f" release-apks/oggauer-gemeindetrommler-universal.apk
|
|
break
|
|
fi
|
|
done
|
|
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
|