185 lines
7.4 KiB
YAML
185 lines
7.4 KiB
YAML
name: Build Android APK
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- master
|
|
- 'refactor/**'
|
|
tags:
|
|
- 'v*'
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
- master
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
build-android:
|
|
name: Build Release APKs
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: ghcr.io/cirruslabs/flutter:3.19.3
|
|
options: --privileged
|
|
steps:
|
|
- 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
|
|
git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
|
git config --global --add safe.directory '*'
|
|
|
|
# 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"
|
|
|
|
QEMU_BIN=$(command -v qemu-x86_64-static || command -v qemu-x86_64)
|
|
|
|
# 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
|
|
for dir in /sdks/flutter/bin/cache/artifacts/engine/android-*; do
|
|
if [ -d "$dir/linux-x64" ]; then
|
|
mkdir -p "$dir/linux-arm64"
|
|
printf '#!/bin/sh\nSCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"\nexec %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 and installing transparent QEMU execution interceptor..."
|
|
gcc -O2 -shared -fPIC -o /usr/local/lib/libqemu_intercept.so scripts/ci/qemu_intercept.c -ldl
|
|
echo "/usr/local/lib/libqemu_intercept.so" > /etc/ld.so.preload
|
|
echo "Installed transparent QEMU execution interceptor into /etc/ld.so.preload"
|
|
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: |
|
|
ARCH=$(uname -m)
|
|
if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
|
|
(
|
|
while true; do
|
|
for aapt2_bin in $(find /root/.gradle /opt/android-sdk-linux -type f -name "aapt2" 2>/dev/null); do
|
|
if [ -f "$aapt2_bin" ] && ! [ -f "${aapt2_bin}.orig" ]; then
|
|
if head -c 4 "$aapt2_bin" 2>/dev/null | grep -q 'ELF'; then
|
|
echo "Wrapping newly extracted AAPT2: $aapt2_bin"
|
|
mv "$aapt2_bin" "${aapt2_bin}.orig"
|
|
printf '#!/bin/sh\nexec /usr/bin/qemu-x86_64-static -L /usr/x86_64-linux-gnu "$0.orig" "$@"\n' > "$aapt2_bin"
|
|
chmod +x "$aapt2_bin" "${aapt2_bin}.orig"
|
|
fi
|
|
fi
|
|
done
|
|
sleep 0.5
|
|
done
|
|
) &
|
|
AAPT2_WATCHER_PID=$!
|
|
echo "AAPT2 Watcher started with PID $AAPT2_WATCHER_PID"
|
|
fi
|
|
|
|
flutter build apk --release
|
|
|
|
if [ -n "$AAPT2_WATCHER_PID" ]; then
|
|
kill "$AAPT2_WATCHER_PID" 2>/dev/null || true
|
|
fi
|
|
|
|
- name: Build Split-per-ABI Release APKs
|
|
run: |
|
|
ARCH=$(uname -m)
|
|
if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
|
|
(
|
|
while true; do
|
|
for aapt2_bin in $(find /root/.gradle /opt/android-sdk-linux -type f -name "aapt2" 2>/dev/null); do
|
|
if [ -f "$aapt2_bin" ] && ! [ -f "${aapt2_bin}.orig" ]; then
|
|
if head -c 4 "$aapt2_bin" 2>/dev/null | grep -q 'ELF'; then
|
|
echo "Wrapping newly extracted AAPT2: $aapt2_bin"
|
|
mv "$aapt2_bin" "${aapt2_bin}.orig"
|
|
printf '#!/bin/sh\nexec /usr/bin/qemu-x86_64-static -L /usr/x86_64-linux-gnu "$0.orig" "$@"\n' > "$aapt2_bin"
|
|
chmod +x "$aapt2_bin" "${aapt2_bin}.orig"
|
|
fi
|
|
fi
|
|
done
|
|
sleep 0.5
|
|
done
|
|
) &
|
|
AAPT2_WATCHER_PID=$!
|
|
fi
|
|
|
|
flutter build apk --release --split-per-abi
|
|
|
|
if [ -n "$AAPT2_WATCHER_PID" ]; then
|
|
kill "$AAPT2_WATCHER_PID" 2>/dev/null || true
|
|
fi
|
|
|
|
- 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-release.apk
|
|
fi
|
|
# Copy split APKs
|
|
if [ -f build/app/outputs/flutter-apk/app-arm64-v8a-release.apk ]; then
|
|
cp build/app/outputs/flutter-apk/app-arm64-v8a-release.apk release-apks/oggauer-gemeindetrommler-arm64-v8a.apk
|
|
fi
|
|
if [ -f build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk ]; then
|
|
cp build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk release-apks/oggauer-gemeindetrommler-armeabi-v7a.apk
|
|
fi
|
|
if [ -f build/app/outputs/flutter-apk/app-x86_64-release.apk ]; then
|
|
cp build/app/outputs/flutter-apk/app-x86_64-release.apk release-apks/oggauer-gemeindetrommler-x86_64.apk
|
|
fi
|
|
echo "=== Generated APK Artifacts ==="
|
|
ls -lah release-apks/
|
|
|
|
- name: Upload APKs to Gitea Artifacts
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: oggauer-gemeindetrommler-apks
|
|
path: release-apks/*.apk
|
|
retention-days: 30
|