Files
daily-notification-plugin/test-apps/BUILD_PROCESS.md
Matthew Raymer d9bdeb6d02 refactor(android)!: restructure to standard Capacitor plugin layout
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.
2025-11-05 08:08:37 +00:00

236 lines
6.8 KiB
Markdown

# 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`):
```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`):
```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-android` project module
### Build Process
1. **Gradle resolves plugin project** - Finds plugin at `../../android`
2. **Gradle builds plugin module** - Compiles plugin Java code to AAR (internally)
3. **Gradle builds app module** - Compiles app code
4. **Gradle links plugin** - Includes plugin classes in app APK
5. **Final output**: `app/build/outputs/apk/debug/app-debug.apk`
### Build Commands
```bash
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`):
```json
{
"dependencies": {
"@timesafari/daily-notification-plugin": "file:../../"
}
}
```
**Capacitor Auto-Configuration**:
- `npx cap sync android` automatically:
1. Installs plugin from `file:../../``node_modules/@timesafari/daily-notification-plugin/`
2. Generates `capacitor.settings.gradle` with plugin reference
3. Generates `capacitor.build.gradle` with plugin dependency
4. Generates `capacitor.plugins.json` with plugin registration
**Plugin Reference** (`capacitor.settings.gradle` - auto-generated):
```gradle
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):
```gradle
dependencies {
implementation project(':timesafari-daily-notification-plugin')
}
```
### Build Process
1. **npm install** - Installs plugin from `file:../../` to `node_modules/`
2. **npm run build** - Builds Vue 3 web app → `dist/`
3. **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`
4. **Fix script runs** - Verifies plugin path is correct (post-sync hook)
5. **Gradle builds** - Plugin is built as part of app build
6. **Final output**: `android/app/build/outputs/apk/debug/app-debug.apk`
### Build Commands
```bash
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.gradle` points to `android/` (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 install` to install plugin
- Requires `npx cap sync android` to configure build
- Plugin installed to `node_modules/` like any npm package
---
## Verification
### Check Plugin is Included
```bash
# 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
```bash
# Vue app only
cat test-apps/daily-notification-test/android/app/src/main/assets/capacitor.plugins.json
```
Should contain:
```json
[
{
"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.json` has 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!