diff --git a/scripts/build-native.sh b/scripts/build-native.sh index ab7c5c4..686c469 100755 --- a/scripts/build-native.sh +++ b/scripts/build-native.sh @@ -115,11 +115,50 @@ build_plugin_for_test_app() { ln -sf "../../../" "$SYMLINK" fi + # Navigate to test app directory + cd test-apps/daily-notification-test || exit 1 + + # Sync Capacitor Android (creates necessary project structure) + log_info "Syncing Capacitor Android..." + if ! npm run cap:sync:android; then + log_error "Capacitor Android sync failed" + exit 1 + fi + + # Navigate to android directory + cd android || exit 1 + + # Fix capacitor.build.gradle if it references missing cordova.variables.gradle + # This file is auto-generated by Capacitor and may reference files that don't exist + if [ -f "app/capacitor.build.gradle" ]; then + if grep -q "^apply from: \"../capacitor-cordova-android-plugins/cordova.variables.gradle\"" "app/capacitor.build.gradle"; then + # Check if the referenced file actually exists + if [ ! -f "capacitor-cordova-android-plugins/cordova.variables.gradle" ]; then + log_info "🔧 Applying fix to capacitor.build.gradle..." + log_info " Reason: Referenced cordova.variables.gradle doesn't exist" + log_info " Fix: Commenting out problematic 'apply from' line" + + # Apply the fix by commenting out the problematic line + # Handle macOS vs Linux sed differences + if [[ "$OSTYPE" == "darwin"* ]]; then + # macOS sed requires empty string after -i + # Use a simpler approach: just comment out the line + sed -i '' 's|^apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"|// &|' "app/capacitor.build.gradle" + else + # Linux sed + sed -i 's|^apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"|// &|' "app/capacitor.build.gradle" + fi + + log_info "✅ Fix applied successfully" + log_warn "⚠️ Note: This fix will be lost if you run 'npx cap sync' or 'npx cap update'" + fi + fi + fi + # Build the plugin and test app from within the test app's Android project context # This is necessary because Capacitor Android is only available as a project dependency # The plugin will be built automatically as a dependency of the app log_info "Building plugin and test app from test app context..." - cd test-apps/daily-notification-test/android || exit 1 # Build test app (this will automatically build the plugin as a dependency) if ! ./gradlew clean assembleDebug; then