#!/usr/bin/env bash # ============================================================ # Kordant Release AAB Builder # ============================================================ # # Builds a signed Android App Bundle (AAB) for Google Play. # # Usage: # ./scripts/build-release-aab.sh # ./scripts/build-release-aab.sh --variant=prodRelease # ./scripts/build-release-aab.sh --variant=devRelease # # Prerequisites: # - key.properties configured (see key.properties.template) # - Android SDK and build tools installed # - Google Services JSON file in app/ (if using Firebase) # # Output: # - app/build/outputs/bundle/prodRelease/app-prod-release.aab # - app/build/outputs/bundle/devRelease/app-dev-release.aab # ============================================================ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_DIR="$(dirname "$SCRIPT_DIR")" VARIANT="prodRelease" # Parse arguments for arg in "$@"; do case $arg in --variant=*) VARIANT="${arg#*=}" shift ;; --help|-h) echo "Usage: $0 [--variant=prodRelease|devRelease]" echo "" echo "Options:" echo " --variant Build variant (default: prodRelease)" echo " --help Show this help message" exit 0 ;; esac done cd "$PROJECT_DIR" echo "============================================" echo " Kordant Release AAB Builder" echo "============================================" echo "" echo "Variant: $VARIANT" echo "" # Check for key.properties if [ ! -f "key.properties" ]; then echo "ERROR: key.properties not found." echo "" echo "Create it from the template:" echo " cp key.properties.template key.properties" echo " # Then edit key.properties with your credentials" echo "" echo "Or generate a new keystore:" echo " ./scripts/generate-release-key.sh" exit 1 fi # Check for google-services.json (needed for Firebase) if [ ! -f "app/google-services.json" ]; then echo "WARNING: google-services.json not found in app/" echo "Firebase features (FCM, Crashlytics) will not work." echo "Download from Firebase Console → Project Settings → Your apps" echo "" fi # Run the build echo "Building $VARIANT..." echo "" ./gradlew "bundle${VARIANT}" \ --no-daemon \ --parallel \ --build-cache \ -Pandroid.injected.signing.storefile="$(pwd)/kordant-release.keystore" \ 2>&1 | tail -50 BUILD_STATUS=$? if [ $BUILD_STATUS -ne 0 ]; then echo "" echo "ERROR: Build failed with exit code $BUILD_STATUS" echo "" echo "Common issues:" echo " 1. key.properties has wrong credentials" echo " 2. Keystore file missing or corrupted" echo " 3. Android SDK not configured in local.properties" echo " 4. google-services.json missing" exit $BUILD_STATUS fi # Find the AAB AAB_PATH="app/build/outputs/bundle/${VARIANT}/app-${VARIANT}.aab" if [ -f "$AAB_PATH" ]; then AAB_SIZE=$(du -h "$AAB_PATH" | cut -f1) echo "" echo "✓ Build successful!" echo "" echo "AAB: $AAB_PATH" echo "Size: $AAB_SIZE" echo "" echo "Upload to Google Play Console:" echo " 1. Go to Play Console → Testing → Internal testing" echo " 2. Click 'Create new release'" echo " 3. Upload $AAB_PATH" echo "" else echo "" echo "ERROR: AAB not found at expected path: $AAB_PATH" echo "" echo "Looking for any AAB files..." find app/build/outputs/bundle -name "*.aab" 2>/dev/null || echo "No AAB files found." exit 1 fi # Generate bundle report echo "Bundle contents:" echo "" if command -v bundletool &> /dev/null; then bundletool dump manifest --module-path="$AAB_PATH" --dump-mode=MERGED_MANIFEST 2>/dev/null | head -30 || true else echo "(bundletool not installed — install with: sdkmanager \"bundle-tools\")" fi echo "" echo "============================================"