Skip to content

Make Capacitor Cordova plugins optional in Android build#339

Open
2witstudios wants to merge 1 commit intomasterfrom
claude/fix-android-build-script-tXB8t
Open

Make Capacitor Cordova plugins optional in Android build#339
2witstudios wants to merge 1 commit intomasterfrom
claude/fix-android-build-script-tXB8t

Conversation

@2witstudios
Copy link
Owner

@2witstudios 2witstudios commented Feb 2, 2026

Summary

This PR makes the capacitor-cordova-android-plugins module optional in the Android build configuration. The build system now gracefully handles scenarios where this module hasn't been generated yet (e.g., before running cap sync), preventing build failures in fresh checkouts or CI environments.

Key Changes

  • Conditional module inclusion: Modified settings.gradle to only include capacitor-cordova-android-plugins if the directory exists
  • Conditional dependency: Updated app/build.gradle to only add the cordova plugins project dependency when the module is present
  • Conditional repository configuration: Changed the flatDir repository setup to check for cordova libs directory existence before including it
  • Fallback build configuration: Added new capacitor.build.gradle.fallback file that provides essential Capacitor plugin dependencies when cordova plugins aren't available
  • Conditional gradle application: The build now applies either the full capacitor.build.gradle (when cordova variables exist) or the fallback version

Implementation Details

  • All conditional checks use File.exists() to determine if generated directories are present
  • The fallback configuration includes core Capacitor plugins and custom plugins needed for the app to build successfully
  • Java version compatibility (21) is maintained in both build configurations
  • The postBuildExtras() hook is preserved in the fallback for extensibility
  • Clear comments explain when each configuration is used and how to generate the full config via pnpm sync

This approach enables the Android build to work in fresh clones and CI pipelines while maintaining full functionality once cap sync has been executed.

https://claude.ai/code/session_016GBMtx46cJb7pGZeUDEAq9

Summary by CodeRabbit

  • Infrastructure & Build System
    • Improved Android build reliability with conditional Cordova plugin handling
    • Added fallback build configuration for development scenarios
    • Added Java 21 compatibility support

The Android build was failing when opened before running 'cap sync' because
the capacitor-cordova-android-plugins directory (gitignored) didn't exist.

Changes:
- settings.gradle: Conditionally include cordova plugins project
- build.gradle: Conditionally apply cordova dependencies and libs
- Add fallback gradle config for builds before 'cap sync' is run

https://claude.ai/code/session_016GBMtx46cJb7pGZeUDEAq9
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 2, 2026

📝 Walkthrough

Walkthrough

The pull request introduces conditional handling of Cordova Android plugins across the build configuration. When the Cordova plugins directory exists, it's included normally; otherwise, a fallback configuration is applied to enable builds before capacitor sync operations complete.

Changes

Cohort / File(s) Summary
Cordova Plugin Conditional Build Configuration
apps/android/android/app/build.gradle, apps/android/android/app/capacitor.build.gradle.fallback, apps/android/android/settings.gradle
Replaced unconditional Cordova plugin inclusion with conditional logic across repositories, dependencies, and settings. Added new fallback Gradle configuration file (capacitor.build.gradle.fallback) with Java 21 compatibility and Capacitor dependencies for use when cordova.variables.gradle is absent. Comments document conditional behavior and explain fallback activation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A fallback path the rabbit did find,
When Cordova plugins were hard to bind,
Conditional checks, both old and new,
Let builds succeed before sync is through! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main objective: making Capacitor Cordova plugins optional in the Android build, which is the core change across all modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/fix-android-build-script-tXB8t

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants