Files
SpotiFLAC-Mobile/scripts/build_android.sh
T
zarzet 5d24a76e85 build(l10n): generate only the shipped languages, compactly
flutter gen-l10n wrote a class for each of the 21 ARB files, and every
class repeated the English text of each message its language has not
translated. The app only offers the 13 languages of
supported_locales.dart.

scripts/gen_l10n.dart writes those 13 only. Each language class extends
the English one and overrides just the messages whose text differs, and
the bare es, pt and zh classes are left out where only a country
variant ships. For the 13 languages every message resolves to the same
text as before (compared across all 2989 messages).

Flutter no longer generates the files: l10n.yaml is gone and pubspec
sets generate: false, because a root l10n.yaml makes every build run
Flutter's own generator. Run `dart scripts/gen_l10n.dart` after ARB
changes and once in a new checkout; build_android.sh does it too. The
script also drops the records of earlier Flutter-generated outputs from
.dart_tool, which made the next build delete the files as stale.

locale_config.xml lists the same 13 languages for Android's per-app
language setting. The Arabic layout test brings its own delegate, as
the app ships no right-to-left language. build_android.sh also passes
MORNYE_MOBILE, which a later commit reads.
2026-11-22 00:14:03 +07:00

126 lines
4.4 KiB
Bash

#!/usr/bin/env bash
# Build the supported Android release APKs for Mornye.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
OUTPUT_DIR="$PROJECT_DIR/build/app/outputs/flutter-apk"
FLUTTER_ARGS=()
PRODUCTION_BUILD=0
LITE_BUILD=0
for argument in "$@"; do
case "$argument" in
--production) PRODUCTION_BUILD=1 ;;
--lite) LITE_BUILD=1; export MORNYE_DISCORD_SDK=0 ;;
--target-platform|--target-platform=*|--split-per-abi|--no-split-per-abi)
echo "Error: set MORNYE_RUST_ANDROID_ABIS to select the release APK architectures." >&2
exit 1
;;
*) FLUTTER_ARGS+=("$argument") ;;
esac
done
if [[ "$PRODUCTION_BUILD" == "1" ]]; then
if [[ "$LITE_BUILD" == "1" ]]; then
echo "Error: production builds require Discord; --production cannot be combined with --lite." >&2
exit 1
fi
export MORNYE_DISCORD_SDK=1
fi
case "${MORNYE_DISCORD_SDK:-1}" in
0|1) ;;
*) echo "Error: MORNYE_DISCORD_SDK must be 0 (Lite) or 1 (full)." >&2; exit 1 ;;
esac
ANDROID_ABIS_RAW="${MORNYE_RUST_ANDROID_ABIS-arm64-v8a,armeabi-v7a}"
case "$ANDROID_ABIS_RAW" in
arm64-v8a|armeabi-v7a|arm64-v8a,armeabi-v7a|armeabi-v7a,arm64-v8a) ;;
*)
echo "Error: MORNYE_RUST_ANDROID_ABIS must contain arm64-v8a and/or armeabi-v7a, comma-separated without spaces or duplicates." >&2
exit 1
;;
esac
export MORNYE_RUST_ANDROID_ABIS="$ANDROID_ABIS_RAW"
IFS=',' read -r -a ANDROID_ABIS <<< "$ANDROID_ABIS_RAW"
TARGET_PLATFORMS=()
for abi in "${ANDROID_ABIS[@]}"; do
case "$abi" in
arm64-v8a) TARGET_PLATFORMS+=(android-arm64) ;;
armeabi-v7a) TARGET_PLATFORMS+=(android-arm) ;;
esac
done
TARGET_PLATFORM_LIST="$(IFS=','; echo "${TARGET_PLATFORMS[*]}")"
if [[ "$PRODUCTION_BUILD" == "1" ]]; then
SDK_ROOT="$PROJECT_DIR/third_party/mornye_discord/sdk"
for sdk_file in discord_partner_sdk.aar notices/Discord-License-Notices.txt android/prefab/modules/discord_partner_sdk/include/discordpp.h; do
if [[ ! -f "$SDK_ROOT/$sdk_file" ]]; then
echo "Error: production requires the staged Discord SDK ($sdk_file). Run scripts/setup_discord_sdk.sh with the official SDK first." >&2
exit 1
fi
done
for abi in "${ANDROID_ABIS[@]}"; do
if [[ ! -f "$SDK_ROOT/android/jni/$abi/libdiscord_partner_sdk.so" ]]; then
echo "Error: production requires the Discord SDK library for $abi." >&2
exit 1
fi
done
fi
AUDIT_FLAGS=()
if [[ "${MORNYE_DISCORD_SDK:-1}" != "0" && -f "$PROJECT_DIR/third_party/mornye_discord/sdk/discord_partner_sdk.aar" ]]; then
AUDIT_FLAGS+=(--discord-sdk)
fi
cd "$PROJECT_DIR"
if [[ -x "$PROJECT_DIR/.fvm/flutter_sdk/bin/flutter" ]]; then
FLUTTER_COMMAND=("$PROJECT_DIR/.fvm/flutter_sdk/bin/flutter")
DART_COMMAND=("$PROJECT_DIR/.fvm/flutter_sdk/bin/dart")
elif command -v fvm >/dev/null 2>&1; then
FLUTTER_COMMAND=(fvm flutter)
DART_COMMAND=(fvm dart)
elif command -v flutter >/dev/null 2>&1; then
FLUTTER_COMMAND=(flutter)
DART_COMMAND=(dart)
else
echo "Error: install the Flutter version pinned in .fvmrc with FVM." >&2
exit 1
fi
PINNED_FLUTTER_VERSION="$(python3 -c 'import json, sys; print(json.load(open(sys.argv[1]))["flutter"])' "$PROJECT_DIR/.fvmrc")"
FLUTTER_VERSION="$("${FLUTTER_COMMAND[@]}" --version --machine | python3 -c 'import json, sys; print(json.load(sys.stdin)["frameworkVersion"])')"
if [[ "$FLUTTER_VERSION" != "$PINNED_FLUTTER_VERSION" ]]; then
echo "Error: Flutter $PINNED_FLUTTER_VERSION is required; found $FLUTTER_VERSION." >&2
exit 1
fi
"${DART_COMMAND[@]}" scripts/prepare_flutter_sdk.dart
"${DART_COMMAND[@]}" scripts/gen_l10n.dart
BUILD_GIT_COMMIT="$(git rev-parse --short=8 HEAD)"
"${FLUTTER_COMMAND[@]}" build apk \
--release \
--obfuscate \
--split-debug-info "$PROJECT_DIR/build/symbols/android" \
--split-per-abi \
--target-platform "$TARGET_PLATFORM_LIST" \
--dart-define="GIT_COMMIT=$BUILD_GIT_COMMIT" \
--dart-define="MORNYE_MOBILE=true" \
${FLUTTER_ARGS[@]+"${FLUTTER_ARGS[@]}"}
for target in "${ANDROID_ABIS[@]}" universal; do
apk="app-$target-release.apk"
abis="$target"
if [[ "$target" == "universal" ]]; then
apk=app-release.apk
abis="$ANDROID_ABIS_RAW"
fi
if [[ ! -f "$OUTPUT_DIR/$apk" ]]; then
echo "Error: expected APK was not created: $OUTPUT_DIR/$apk" >&2
exit 1
fi
python3 scripts/check_backend_apk.py "$OUTPUT_DIR/$apk" \
--backend rust --abis "$abis" ${AUDIT_FLAGS[@]+"${AUDIT_FLAGS[@]}"}
done
echo "Built Android release APKs in $OUTPUT_DIR"