Restructure Android project from nested module layout to standard Capacitor plugin structure following community conventions. Structure Changes: - Move plugin code from android/plugin/ to android/src/main/java/ - Move test app from android/app/ to test-apps/android-test-app/app/ - Remove nested android/plugin module structure - Remove nested android/app test app structure Build Infrastructure: - Add Gradle wrapper files (gradlew, gradlew.bat, gradle/wrapper/) - Transform android/build.gradle from root project to library module - Update android/settings.gradle for standalone plugin builds - Add android/gradle.properties with AndroidX configuration - Add android/consumer-rules.pro for ProGuard rules Configuration Updates: - Add prepare script to package.json for automatic builds on npm install - Update package.json version to 1.0.1 - Update android/build.gradle to properly resolve Capacitor dependencies - Update test-apps/android-test-app/settings.gradle with correct paths - Remove android/variables.gradle (hardcode values in build.gradle) Documentation: - Update BUILDING.md with new structure and build process - Update INTEGRATION_GUIDE.md to reflect standard structure - Update README.md to remove path fix warnings - Add test-apps/BUILD_PROCESS.md documenting test app build flows Test App Configuration: - Fix android-test-app to correctly reference plugin and Capacitor - Remove capacitor-cordova-android-plugins dependency (not needed) - Update capacitor.settings.gradle path verification in fix script BREAKING CHANGE: Plugin now uses standard Capacitor Android structure. Consuming apps must update their capacitor.settings.gradle to reference android/ instead of android/plugin/. This is automatically handled by Capacitor CLI for apps using standard plugin installation.
6.8 KiB
Test Apps Build Process Review
Summary
Both test apps are configured to automatically build the plugin as part of their build process. The plugin is included as a Gradle project dependency, so Gradle handles building it automatically.
Test App 1: android-test-app (Standalone Android)
Location: test-apps/android-test-app/
Configuration
Plugin Reference (settings.gradle):
// Reference plugin from root project
def pluginPath = new File(settingsDir.parentFile.parentFile, 'android')
include ':daily-notification-plugin'
project(':daily-notification-plugin').projectDir = pluginPath
Plugin Dependency (app/build.gradle):
dependencies {
implementation project(':capacitor-android')
implementation project(':daily-notification-plugin') // ✅ Plugin included
// Plugin dependencies also included
}
Capacitor Setup:
- References Capacitor from
daily-notification-test/node_modules/(shared dependency) - Includes
:capacitor-androidproject module
Build Process
- Gradle resolves plugin project - Finds plugin at
../../android - Gradle builds plugin module - Compiles plugin Java code to AAR (internally)
- Gradle builds app module - Compiles app code
- Gradle links plugin - Includes plugin classes in app APK
- Final output:
app/build/outputs/apk/debug/app-debug.apk
Build Commands
cd test-apps/android-test-app
# Build debug APK (builds plugin automatically)
./gradlew assembleDebug
# Build release APK
./gradlew assembleRelease
# Clean build
./gradlew clean
# List tasks
./gradlew tasks
Prerequisites
- ✅ Gradle wrapper present (
gradlew,gradlew.bat,gradle/wrapper/) - ✅ Capacitor must be installed in
daily-notification-test/node_modules/(shared) - ✅ Plugin must exist at root
android/directory
Test App 2: daily-notification-test (Vue 3 + Capacitor)
Location: test-apps/daily-notification-test/
Configuration
Plugin Installation (package.json):
{
"dependencies": {
"@timesafari/daily-notification-plugin": "file:../../"
}
}
Capacitor Auto-Configuration:
npx cap sync androidautomatically:- Installs plugin from
file:../../→node_modules/@timesafari/daily-notification-plugin/ - Generates
capacitor.settings.gradlewith plugin reference - Generates
capacitor.build.gradlewith plugin dependency - Generates
capacitor.plugins.jsonwith plugin registration
- Installs plugin from
Plugin Reference (capacitor.settings.gradle - auto-generated):
include ':timesafari-daily-notification-plugin'
project(':timesafari-daily-notification-plugin').projectDir =
new File('../node_modules/@timesafari/daily-notification-plugin/android')
Plugin Dependency (capacitor.build.gradle - auto-generated):
dependencies {
implementation project(':timesafari-daily-notification-plugin')
}
Build Process
- npm install - Installs plugin from
file:../../tonode_modules/ - npm run build - Builds Vue 3 web app →
dist/ - npx cap sync android - Capacitor:
- Copies web assets to
android/app/src/main/assets/ - Configures plugin in Gradle files
- Registers plugin in
capacitor.plugins.json
- Copies web assets to
- Fix script runs - Verifies plugin path is correct (post-sync hook)
- Gradle builds - Plugin is built as part of app build
- Final output:
android/app/build/outputs/apk/debug/app-debug.apk
Build Commands
cd test-apps/daily-notification-test
# Initial setup (one-time)
npm install # Installs plugin from file:../../
npx cap sync android # Configures Android build
# Development workflow
npm run build # Builds Vue 3 web app
npx cap sync android # Syncs web assets + plugin config
cd android
./gradlew assembleDebug # Builds Android app (includes plugin)
# Or use Capacitor CLI (does everything)
npx cap run android # Builds web + syncs + builds Android + runs
Post-Install Hook
The postinstall script (scripts/fix-capacitor-plugins.js) automatically:
- ✅ Verifies plugin is registered in
capacitor.plugins.json - ✅ Verifies plugin path in
capacitor.settings.gradlepoints toandroid/(standard structure) - ✅ Fixes path if it incorrectly points to old
android/plugin/structure
Key Points
✅ Both Apps Build Plugin Automatically
- No manual plugin build needed - Gradle handles it
- Plugin is a project dependency - Built before the app
- Standard Gradle behavior - Works like any Android library module
✅ Plugin Structure is Standard
- Plugin location:
android/src/main/java/...(standard Capacitor structure) - No path fixes needed - Capacitor auto-generates correct paths
- Works with
npx cap sync- No manual configuration required
✅ Build Dependencies
android-test-app:
- Requires Capacitor from
daily-notification-test/node_modules/(shared) - References plugin directly from root
android/directory
daily-notification-test:
- Requires
npm installto install plugin - Requires
npx cap sync androidto configure build - Plugin installed to
node_modules/like any npm package
Verification
Check Plugin is Included
# For android-test-app
cd test-apps/android-test-app
./gradlew :app:dependencies | grep daily-notification
# For daily-notification-test
cd test-apps/daily-notification-test/android
./gradlew :app:dependencies | grep timesafari
Check Plugin Registration
# Vue app only
cat test-apps/daily-notification-test/android/app/src/main/assets/capacitor.plugins.json
Should contain:
[
{
"name": "DailyNotification",
"classpath": "com.timesafari.dailynotification.DailyNotificationPlugin"
}
]
Troubleshooting
android-test-app: "Capacitor not found"
Solution: Run npm install in test-apps/daily-notification-test/ first to install Capacitor dependencies.
android-test-app: "Plugin not found"
Solution: Verify android/build.gradle exists at the root project level.
daily-notification-test: Plugin path wrong
Solution: Run node scripts/fix-capacitor-plugins.js after npx cap sync android. The script now verifies/fixes the path to use standard android/ structure.
Both: Build succeeds but plugin doesn't work
Solution:
- Check
capacitor.plugins.jsonhas plugin registered - Verify plugin classes are in the APK:
unzip -l app-debug.apk | grep DailyNotification
Summary
✅ Both test apps handle plugin building automatically
✅ Plugin uses standard Capacitor structure (android/src/main/java/)
✅ No manual plugin builds required - Gradle handles dependencies
✅ Build processes are configured correctly - Ready to use
The test apps are properly configured to build and test the plugin!