diff --git a/test-apps/daily-notification-test/scripts/build.sh b/test-apps/daily-notification-test/scripts/build.sh index 23baab9..96b2912 100755 --- a/test-apps/daily-notification-test/scripts/build.sh +++ b/test-apps/daily-notification-test/scripts/build.sh @@ -108,7 +108,8 @@ check_requirements() { # Check Android requirements if building Android if [ "$BUILD_ALL" = true ] || [ "$BUILD_ANDROID" = true ]; then if ! command -v adb &> /dev/null; then - log_warn "Android SDK not found (adb not in PATH). Android build will be skipped." + log_warn "Android SDK tools not found (adb not in PATH)." + log_warn "APK can still be built, but install/launch requires adb." else log_info "✅ Android SDK: $(adb version | head -1)" fi @@ -238,28 +239,105 @@ if [ "$BUILD_ALL" = true ] || [ "$BUILD_IOS" = true ]; then fi fi +# Find Android SDK location +find_android_sdk() { + local android_dir="" + local local_props="$PROJECT_DIR/android/local.properties" + + # Check environment variables first + if [ -n "$ANDROID_HOME" ] && [ -d "$ANDROID_HOME" ]; then + android_dir="$ANDROID_HOME" + log_info "Found Android SDK via ANDROID_HOME: $android_dir" + elif [ -n "$ANDROID_SDK_ROOT" ] && [ -d "$ANDROID_SDK_ROOT" ]; then + android_dir="$ANDROID_SDK_ROOT" + log_info "Found Android SDK via ANDROID_SDK_ROOT: $android_dir" + fi + + # Check existing local.properties + if [ -z "$android_dir" ] && [ -f "$local_props" ]; then + # Temporarily disable exit on error for grep (may not find match) + set +e + sdk_line=$(grep "^sdk.dir=" "$local_props" 2>/dev/null) + set -e + if [ -n "$sdk_line" ]; then + android_dir=$(echo "$sdk_line" | cut -d'=' -f2 | sed 's|\\\\|/|g' | sed "s|^~|$HOME|") + if [ -n "$android_dir" ] && [ -d "$android_dir" ]; then + log_info "Found Android SDK in local.properties: $android_dir" + else + android_dir="" + fi + fi + fi + + # Try common locations + if [ -z "$android_dir" ]; then + # macOS default location + if [ -d "$HOME/Library/Android/sdk" ]; then + android_dir="$HOME/Library/Android/sdk" + log_info "Found Android SDK in default macOS location: $android_dir" + # Linux default location + elif [ -d "$HOME/Android/Sdk" ]; then + android_dir="$HOME/Android/Sdk" + log_info "Found Android SDK in default Linux location: $android_dir" + fi + fi + + # Create/update local.properties if SDK found + if [ -n "$android_dir" ]; then + # Normalize path (convert to forward slashes, expand ~) + android_dir=$(echo "$android_dir" | sed 's|\\\\|/|g' | sed "s|^~|$HOME|") + + # Create local.properties with SDK location + mkdir -p "$(dirname "$local_props")" + echo "## This file is automatically generated by build script" > "$local_props" + echo "## Location: $android_dir" >> "$local_props" + echo "sdk.dir=$android_dir" >> "$local_props" + log_info "✅ Configured Android SDK in local.properties" + return 0 + else + log_error "Android SDK not found!" + log_error "Please set one of the following:" + log_error " 1. ANDROID_HOME environment variable" + log_error " 2. ANDROID_SDK_ROOT environment variable" + log_error " 3. Create android/local.properties with: sdk.dir=/path/to/android/sdk" + log_error "" + log_error "Common SDK locations:" + log_error " macOS: ~/Library/Android/sdk" + log_error " Linux: ~/Android/Sdk" + return 1 + fi +} + # Android build if [ "$BUILD_ALL" = true ] || [ "$BUILD_ANDROID" = true ]; then log_step "Building Android app..." - # Check for Android SDK - if ! command -v adb &> /dev/null; then - log_warn "adb not found. Android SDK may not be installed." - log_warn "Skipping Android build. Install Android SDK to build Android." - else - cd "$PROJECT_DIR/android" + # Ensure Android SDK is configured + if ! find_android_sdk; then + log_error "Cannot build Android app without SDK location" + exit 1 + fi + + cd "$PROJECT_DIR/android" + + # Build APK (Gradle doesn't require adb for building) + if ./gradlew :app:assembleDebug; then + log_info "Android APK built successfully" - # Build APK - if ./gradlew :app:assembleDebug; then - log_info "Android APK built successfully" + APK_PATH="$PROJECT_DIR/android/app/build/outputs/apk/debug/app-debug.apk" + + if [ -f "$APK_PATH" ]; then + log_info "APK location: $APK_PATH" - APK_PATH="$PROJECT_DIR/android/app/build/outputs/apk/debug/app-debug.apk" - - if [ -f "$APK_PATH" ]; then - log_info "APK location: $APK_PATH" - - # Run on emulator if requested - if [ "$RUN_ALL" = true ] || [ "$RUN_ANDROID" = true ]; then + # Run on emulator if requested (requires adb) + if [ "$RUN_ALL" = true ] || [ "$RUN_ANDROID" = true ]; then + # Check for Android SDK tools (adb) + if ! command -v adb &> /dev/null; then + log_warn "adb not found in PATH. Cannot install/launch app." + log_warn "APK built successfully, but install/launch requires Android SDK." + log_info "To install manually: adb install -r $APK_PATH" + log_info "Or add Android SDK platform-tools to your PATH." + else log_step "Installing and launching Android app..." # Check for running emulator @@ -283,16 +361,16 @@ if [ "$BUILD_ALL" = true ] || [ "$BUILD_ANDROID" = true ]; then fi fi fi - else - log_error "APK not found at expected location: $APK_PATH" fi else - log_error "Android build failed" - exit 1 + log_error "APK not found at expected location: $APK_PATH" fi - - cd "$PROJECT_DIR" + else + log_error "Android build failed" + exit 1 fi + + cd "$PROJECT_DIR" fi # iOS build