#!/bin/bash # Android Test App Setup Script echo "๐Ÿš€ Setting up Android Test App..." # Check if we're in the right directory if [ ! -d "android-test" ]; then echo "โŒ Error: android-test directory not found!" echo "Please run this script from the test-apps directory" exit 1 fi cd android-test # Check Node.js version echo "๐Ÿ” Checking Node.js version..." node_version=$(node --version 2>/dev/null) if [ $? -ne 0 ]; then echo "โŒ Error: Node.js not found!" echo "Please install Node.js 18+ from https://nodejs.org/" exit 1 fi echo "โœ… Node.js version: $node_version" # Install dependencies echo "๐Ÿ“ฆ Installing dependencies..." npm install if [ $? -ne 0 ]; then echo "โŒ Error: Failed to install dependencies!" exit 1 fi # Install Capacitor CLI globally if not present if ! command -v cap &> /dev/null; then echo "๐Ÿ”ง Installing Capacitor CLI globally..." npm install -g @capacitor/cli if [ $? -ne 0 ]; then echo "โŒ Error: Failed to install Capacitor CLI!" exit 1 fi else echo "โœ… Capacitor CLI already installed" fi # Initialize Capacitor (only if not already initialized) if [ ! -f "capacitor.config.ts" ]; then echo "โšก Initializing Capacitor..." npx cap init "Daily Notification Android Test" "com.timesafari.dailynotification.androidtest" if [ $? -ne 0 ]; then echo "โŒ Error: Failed to initialize Capacitor!" exit 1 fi else echo "โœ… Capacitor already initialized" fi # Add Android platform (only if not already added) if [ ! -d "android" ]; then echo "๐Ÿ“ฑ Adding Android platform..." npx cap add android if [ $? -ne 0 ]; then echo "โŒ Error: Failed to add Android platform!" echo "Make sure Android Studio and Android SDK are installed" exit 1 fi else echo "โœ… Android platform already added" fi # Build web assets echo "๐Ÿ”จ Building web assets..." npm run build if [ $? -ne 0 ]; then echo "โŒ Error: Failed to build web assets!" exit 1 fi # Sync to native echo "๐Ÿ”„ Syncing to native..." npx cap sync android if [ $? -ne 0 ]; then echo "โŒ Error: Failed to sync to native!" echo "๐Ÿ”ง Attempting to fix Gradle sync issues..." # Fix common Gradle sync issues cd android ./gradlew clean ./gradlew --stop # Clear Gradle cache if needed if [ -d ~/.gradle/wrapper/dists/gradle-9.0-milestone-1* ]; then echo "๐Ÿงน Clearing incompatible Gradle cache..." rm -rf ~/.gradle/wrapper/dists/gradle-9.0-milestone-1* fi cd .. # Try sync again echo "๐Ÿ”„ Retrying sync..." npx cap sync android if [ $? -ne 0 ]; then echo "โŒ Error: Sync still failing after cleanup" echo "๐Ÿ“‹ See GRADLE_TROUBLESHOOTING.md for manual fixes" exit 1 fi fi echo "" echo "โœ… Android test app setup complete!" echo "" echo "๐Ÿ“‹ Prerequisites check:" echo "- Android Studio installed: $(command -v studio &> /dev/null && echo 'โœ…' || echo 'โŒ')" echo "- Android SDK configured: $(echo $ANDROID_HOME | grep -q . && echo 'โœ…' || echo 'โŒ')" echo "" echo "๐Ÿš€ Next steps:" echo "1. Open Android Studio: npx cap open android" echo "2. Run on device/emulator: npx cap run android" echo "3. Or test web version: npm run dev" echo "" echo "๐Ÿ”ง Troubleshooting:" echo "- If Android Studio doesn't open, install it from https://developer.android.com/studio" echo "- If sync fails, check Android SDK installation" echo "- For web testing, run: npm run dev"