docs: add comprehensive documentation for automatic capacitor.build.gradle fix

- Add detailed inline documentation in build-native.sh explaining the problem, why it happens, and the solution
- Update fix-capacitor-build.sh with comprehensive header documentation
- Include clear explanations of when the fix gets overwritten and how to restore it
- Add user-friendly output with emojis and clear messaging
- Document the automatic fix process with step-by-step explanations

This provides complete transparency about what the scripts do and why,
making it easy for developers to understand and maintain the fix.
This commit is contained in:
Matthew Raymer
2025-10-12 06:17:42 +00:00
parent a6d7d39c34
commit fc031bf341
2 changed files with 104 additions and 9 deletions

View File

@@ -82,12 +82,54 @@ build_android() {
log_warn "This appears to be a plugin development project"
log_warn "Android test app not properly initialized"
# Fix capacitor.build.gradle if needed
# =============================================================================
# AUTOMATIC FIX: capacitor.build.gradle for Plugin Development Projects
# =============================================================================
#
# PROBLEM: The capacitor.build.gradle file is auto-generated by Capacitor CLI
# and includes a line that tries to load a file that doesn't exist in plugin
# development projects:
# apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
#
# WHY THIS HAPPENS:
# - This file is generated by 'npx cap sync', 'npx cap update', etc.
# - It assumes a full Capacitor app with proper plugin integration
# - Plugin development projects don't have the full Capacitor setup
#
# THE FIX:
# - Comment out the problematic line to prevent build failures
# - Add explanatory comment about why it's commented out
# - This fix gets applied automatically every time the build script runs
#
# WHEN THIS FIX GETS OVERWRITTEN:
# - Running 'npx cap sync' will regenerate the file and remove our fix
# - Running 'npx cap update' will regenerate the file and remove our fix
# - Running 'npx cap add android' will regenerate the file and remove our fix
#
# HOW TO RESTORE THE FIX:
# - Run this build script again (it will reapply the fix automatically)
# - Or run: ./scripts/fix-capacitor-build.sh
# - Or manually comment out the problematic line
#
# =============================================================================
if [ -f "app/capacitor.build.gradle" ]; then
if grep -q "^apply from: \"../capacitor-cordova-android-plugins/cordova.variables.gradle\"" "app/capacitor.build.gradle"; then
log_info "Fixing capacitor.build.gradle for plugin development project..."
log_info "🔧 Applying automatic fix to capacitor.build.gradle..."
log_info " Reason: Plugin development project missing Capacitor integration files"
log_info " Fix: Commenting out problematic 'apply from' line"
# Apply the fix by commenting out the problematic line
sed -i 's/^apply from: "\.\.\/capacitor-cordova-android-plugins\/cordova\.variables\.gradle"/\/\/ Plugin development project - no Capacitor integration files needed\n\/\/ &/' "app/capacitor.build.gradle"
log_info "✅ Fix applied successfully"
log_warn "⚠️ Note: This fix will be lost if you run 'npx cap sync' or 'npx cap update'"
log_info "💡 To restore the fix later, run this build script again or use: ./scripts/fix-capacitor-build.sh"
else
log_info " capacitor.build.gradle already has the fix applied"
fi
else
log_warn "⚠️ capacitor.build.gradle not found - this may indicate a different project structure"
fi
log_warn "Plugin source code has been built successfully"

View File

@@ -1,22 +1,75 @@
#!/bin/bash
# Fix for capacitor.build.gradle in plugin development projects
# This script should be run after any 'npx cap sync' or 'npx cap update'
# =============================================================================
# FIX SCRIPT: capacitor.build.gradle for Plugin Development Projects
# =============================================================================
#
# PURPOSE: This script fixes a common issue in Capacitor plugin development
# projects where the auto-generated capacitor.build.gradle file tries to load
# a file that doesn't exist, causing build failures.
#
# WHEN TO USE:
# - After running 'npx cap sync'
# - After running 'npx cap update'
# - After running 'npx cap add android'
# - After any Capacitor CLI command that regenerates integration files
# - When you get build errors about missing cordova.variables.gradle
#
# WHAT IT DOES:
# - Finds the problematic line in capacitor.build.gradle
# - Comments it out with an explanatory comment
# - Prevents build failures in plugin development projects
#
# THE PROBLEM:
# Capacitor generates this line in capacitor.build.gradle:
# apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
# But plugin development projects don't have this file, causing:
# "Could not read script '.../cordova.variables.gradle' as it does not exist"
#
# THE FIX:
# Comments out the problematic line and adds explanation:
# // Plugin development project - no Capacitor integration files needed
# // apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
#
# =============================================================================
set -e
CAPACITOR_BUILD_GRADLE="android/app/capacitor.build.gradle"
echo "🔧 DailyNotification Plugin - Capacitor Build Fix Script"
echo "========================================================"
if [ -f "$CAPACITOR_BUILD_GRADLE" ]; then
echo "🔧 Fixing capacitor.build.gradle for plugin development project..."
echo "📁 Found capacitor.build.gradle at: $CAPACITOR_BUILD_GRADLE"
# Comment out the problematic line if it exists and isn't already commented
# Check if the problematic line exists and isn't already commented
if grep -q "^apply from: \"../capacitor-cordova-android-plugins/cordova.variables.gradle\"" "$CAPACITOR_BUILD_GRADLE"; then
echo "🔧 Applying fix to capacitor.build.gradle..."
echo " Problem: Line tries to load non-existent cordova.variables.gradle"
echo " Solution: Commenting out the problematic line"
# Apply the fix by commenting out the problematic line
sed -i 's/^apply from: "\.\.\/capacitor-cordova-android-plugins\/cordova\.variables\.gradle"/\/\/ Plugin development project - no Capacitor integration files needed\n\/\/ &/' "$CAPACITOR_BUILD_GRADLE"
echo "✅ Fixed capacitor.build.gradle"
echo "✅ Fix applied successfully!"
echo "💡 The problematic line has been commented out with an explanation"
echo "⚠️ Note: This fix will be lost if you run Capacitor CLI commands again"
echo "🔄 To restore the fix later, run this script again or use the build script"
else
echo " capacitor.build.gradle already fixed or doesn't need fixing"
echo " capacitor.build.gradle already has the fix applied or doesn't need fixing"
echo " (The problematic line is either commented out or doesn't exist)"
fi
else
echo "⚠️ capacitor.build.gradle not found at $CAPACITOR_BUILD_GRADLE"
echo "⚠️ capacitor.build.gradle not found at: $CAPACITOR_BUILD_GRADLE"
echo " This may indicate:"
echo " - You're not in the correct directory"
echo " - The Android project structure is different"
echo " - The file hasn't been generated yet"
fi
echo ""
echo "📚 For more information, see:"
echo " - BUILDING.md (troubleshooting section)"
echo " - scripts/build-native.sh (automatic fix documentation)"
echo "========================================================"