- Add SafeArea and SharedImage plugins to capacitor.plugins.json - Create restore-local-plugins.js to persist plugins after cap sync - Integrate plugin restoration into build scripts - Improve Android share intent timing with retry logic - Clean up debug logging while keeping essential error handling - Add documentation for local plugin management Fixes issue where SharedImage plugin wasn't recognized, causing "UNIMPLEMENTED" errors. Image sharing now works correctly on Android.
1.8 KiB
1.8 KiB
Restore Local Capacitor Plugins
Overview
The restore-local-plugins.js script ensures that local custom Capacitor plugins (SafeArea and SharedImage) are automatically restored to android/app/src/main/assets/capacitor.plugins.json after running npx cap sync android.
Why This Is Needed
The capacitor.plugins.json file is auto-generated by Capacitor during npx cap sync and gets overwritten, removing any manually added local plugins. This script automatically restores them.
Usage
Automatic (Recommended)
The script is automatically run by:
./scripts/build-android.sh(aftercap sync)npm run build:capacitor:syncnpm run build:native
Manual
If you run npx cap sync android directly, you can restore plugins manually:
node scripts/restore-local-plugins.js
What It Does
- Reads
android/app/src/main/assets/capacitor.plugins.json - Checks if local plugins (
SafeAreaandSharedImage) are present - Adds any missing local plugins
- Preserves the existing JSON format
Local Plugins
The following local plugins are automatically restored:
- SafeArea:
app.timesafari.safearea.SafeAreaPlugin - SharedImage:
app.timesafari.sharedimage.SharedImagePlugin
Adding New Local Plugins
To add a new local plugin, edit scripts/restore-local-plugins.js and add it to the LOCAL_PLUGINS array:
const LOCAL_PLUGINS = [
// ... existing plugins ...
{
pkg: 'YourPluginName',
classpath: 'app.timesafari.yourpackage.YourPluginClass'
}
];
Notes
- The script is idempotent - running it multiple times won't create duplicates
- The script preserves the existing JSON formatting (tabs, etc.)
- If the plugins file doesn't exist, the script will exit with an error (run
npx cap sync androidfirst)