Overview
CicloVital uses Capacitor to build native mobile applications from the React web app. Capacitor provides a native runtime and bridge that allows web apps to run on iOS and Android while accessing native device features.Capacitor Version
The project uses the following Capacitor packages:package.json
Capacitor 7 is the latest major version with improved performance, better plugin APIs, and enhanced TypeScript support.
Configuration File
The main Capacitor configuration is stored incapacitor.config.json at the project root:
capacitor.config.json
Configuration Properties
| Property | Value | Description |
|---|---|---|
| appId | com.ciclovital.app | Unique identifier for the app (reverse domain format) |
| appName | CicloVital | Display name shown on the device home screen |
| webDir | dist | Directory containing built web assets (Vite output) |
| bundledWebRuntime | false | Uses system WebView instead of bundling Capacitor runtime |
Project Structure
After runningnpx cap add android, the project structure includes:
Core Capacitor Workflow
Build Web Assets
Compile your React app into static files:This creates optimized files in the
dist directory using Vite.Sync with Native Projects
Copy web assets and update native projects:This command:
- Copies
distcontents to native platform asset directories - Updates native dependencies based on installed plugins
- Applies configuration changes from
capacitor.config.json
Open Native IDE
Open the native project in its respective IDE:This opens Android Studio with the
android directory.Capacitor CLI Commands
Essential Commands
Sync vs Copy vs Update
| Command | What It Does |
|---|---|
| sync | Copy web assets + update native dependencies + apply config |
| copy | Copy web assets only (faster for quick iterations) |
| update | Update Capacitor core and official plugins to latest versions |
Native Code Integration
The native Android app extendsBridgeActivity to integrate with Capacitor:
android/app/src/main/java/com/ciclovital/app/MainActivity.java
Permissions
The Android app requests the following permissions inAndroidManifest.xml:
android/app/src/main/AndroidManifest.xml
Additional permissions (camera, location, notifications, etc.) are automatically added by Capacitor plugins when installed.
Installing Capacitor Plugins
Capacitor plugins provide access to native device features. Install plugins as npm packages:Common Official Plugins
Here are some popular Capacitor plugins you might want to add:Camera
Camera
Access the device camera and photo library.
Storage
Storage
Persistent key-value storage.
Geolocation
Geolocation
Access device GPS and location services.
Push Notifications
Push Notifications
Send and receive push notifications.Requires additional Firebase configuration for Android.
Status Bar
Status Bar
Control the device status bar appearance.
Haptics
Haptics
Trigger haptic feedback (vibrations).
Registering Custom Plugins
If you create a custom plugin, register it inMainActivity.java:
Platform-Specific Configuration
You can add platform-specific settings tocapacitor.config.json:
capacitor.config.json
Android-Specific Options
| Option | Description |
|---|---|
| backgroundColor | Default background color for the WebView |
| allowMixedContent | Allow HTTP content in HTTPS pages (not recommended) |
| captureInput | Capture keyboard input events |
| webContentsDebuggingEnabled | Enable Chrome DevTools debugging |
Development Configuration
For development with live reload, temporarily add aserver configuration:
capacitor.config.json
TypeScript Configuration
For TypeScript projects, install type definitions:Updating Capacitor
To update Capacitor to the latest version:Review Migration Guide
Check the Capacitor migration guide for breaking changes between major versions.
Debugging Capacitor Apps
Chrome DevTools (Android)
Native Logs
View native Android logs:Environment-Specific Builds
Manage different configurations for development, staging, and production:Troubleshooting
Plugin Not Found
If a plugin isn’t recognized:WebView Blank Screen
Ensure web assets are built and synced:CORS Errors
Capacitor apps use thecapacitor://localhost scheme, which bypasses CORS. If you see CORS errors, your API server may need to allow this origin, or use Capacitor’s HTTP plugin:
Resources
Capacitor Docs
Official Capacitor documentation
Plugin Registry
Browse available Capacitor plugins
Android Setup
Build and run the Android app
API Reference
Capacitor API documentation
