#!/bin/bash # TimeSafari Android Resource Check Script # Checks for missing Android resources and automatically fixes common issues # Author: Matthew Raymer set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" ANDROID_RES_DIR="$PROJECT_ROOT/android/app/src/main/res" ASSETS_DIR="$PROJECT_ROOT/assets" echo "=== TimeSafari Android Resource Check ===" echo "[$(date '+%Y-%m-%d %H:%M:%S')] [INFO] Checking Android resources" # Function to check if a file exists check_file() { local file="$1" local description="$2" if [ -f "$file" ]; then echo "[✓] $description: $file" return 0 else echo "[✗] $description: $file (MISSING)" return 1 fi } # Function to check if a directory exists and has files check_directory() { local dir="$1" local description="$2" if [ -d "$dir" ] && [ "$(ls -A "$dir" 2>/dev/null)" ]; then echo "[✓] $description: $dir" return 0 else echo "[✗] $description: $dir (MISSING OR EMPTY)" return 1 fi } # Track issues issues_found=0 fixes_applied=0 echo "[INFO] Checking splash screen resources..." # Check splash screen resources if ! check_file "$ANDROID_RES_DIR/drawable/splash.png" "Splash screen (light)"; then if [ -f "$ASSETS_DIR/splash.png" ]; then echo "[FIX] Copying splash.png to Android resources..." cp "$ASSETS_DIR/splash.png" "$ANDROID_RES_DIR/drawable/splash.png" fixes_applied=$((fixes_applied + 1)) else issues_found=$((issues_found + 1)) fi fi if ! check_file "$ANDROID_RES_DIR/drawable/splash_dark.png" "Splash screen (dark)"; then if [ -f "$ASSETS_DIR/splash_dark.png" ]; then echo "[FIX] Copying splash_dark.png to Android resources..." cp "$ASSETS_DIR/splash_dark.png" "$ANDROID_RES_DIR/drawable/splash_dark.png" fixes_applied=$((fixes_applied + 1)) else issues_found=$((issues_found + 1)) fi fi echo "[INFO] Checking launcher icon resources..." # Check launcher icon resources required_icons=( "mipmap-mdpi/ic_launcher.png" "mipmap-hdpi/ic_launcher.png" "mipmap-xhdpi/ic_launcher.png" "mipmap-xxhdpi/ic_launcher.png" "mipmap-xxxhdpi/ic_launcher.png" "mipmap-anydpi-v26/ic_launcher.xml" "mipmap-anydpi-v26/ic_launcher_round.xml" ) missing_icons=0 for icon in "${required_icons[@]}"; do if ! check_file "$ANDROID_RES_DIR/$icon" "Launcher icon: $icon"; then missing_icons=$((missing_icons + 1)) fi done if [ $missing_icons -gt 0 ]; then echo "[FIX] Missing launcher icons detected. Running icon generation script..." if [ -f "$SCRIPT_DIR/generate-android-icons.sh" ]; then "$SCRIPT_DIR/generate-android-icons.sh" fixes_applied=$((fixes_applied + 1)) else echo "[ERROR] Icon generation script not found: $SCRIPT_DIR/generate-android-icons.sh" issues_found=$((issues_found + 1)) fi fi echo "[INFO] Checking Capacitor platform status..." # Check if Android platform is properly initialized if [ ! -d "$PROJECT_ROOT/android" ]; then echo "[ERROR] Android platform directory not found" issues_found=$((issues_found + 1)) elif [ ! -f "$PROJECT_ROOT/android/app/src/main/AndroidManifest.xml" ]; then echo "[ERROR] AndroidManifest.xml not found - platform may be corrupted" issues_found=$((issues_found + 1)) else echo "[✓] Android platform appears to be properly initialized" fi # Check for common build issues echo "[INFO] Checking for common build issues..." # Check for invalid resource names (dashes in filenames) invalid_resources=$(find "$ANDROID_RES_DIR" -name "*-*" -type f 2>/dev/null | grep -E '\.(png|jpg|jpeg|gif|xml)$' || true) if [ -n "$invalid_resources" ]; then echo "[WARNING] Found resources with invalid names (containing dashes):" echo "$invalid_resources" | while read -r file; do echo " - $file" done echo "[INFO] Android resource names must contain only lowercase a-z, 0-9, or underscore" issues_found=$((issues_found + 1)) fi # Summary echo "" echo "=== Resource Check Summary ===" if [ $issues_found -eq 0 ] && [ $fixes_applied -eq 0 ]; then echo "[SUCCESS] All Android resources are present and valid" exit 0 elif [ $fixes_applied -gt 0 ]; then echo "[SUCCESS] Fixed $fixes_applied resource issues automatically" if [ $issues_found -gt 0 ]; then echo "[WARNING] $issues_found issues remain that require manual attention" exit 1 else exit 0 fi else echo "[ERROR] Found $issues_found resource issues that require manual attention" exit 1 fi