This project contains an example of integrating an Ionic Micro Web App (MWA) into an Android application.
- Install Node 22 or newer. The NFC plugin needs it.
- Use JDK 21. The JDK inside Android Studio works. On macOS:
export JAVA_HOME="/Applications/Android Studio.app/Contents/jbr/Contents/Home". - Tell Gradle where the Android SDK is: set
sdk.dirinlocal.properties, or setANDROID_HOME. Android Studio writeslocal.propertieswhen it opens the project. - In the root folder, run
npm ci. - Run
./gradlew assembleDebug, or Run in Android Studio.
Run npm ci again after any change to package.json or package-lock.json. Gradle builds the plugin code inside node_modules.
On a fresh install, the first open of each MWA shows an error page while its live update downloads. Go back and open it again.
The build.gradle (app module) has Gradle tasks that download and unzip the MWA build from Appflow into the assets directory. They run only when you give an Appflow token:
- Install the Appflow CLI.
- Run
./gradlew assembleDebug -PionicToken=<token>orIONIC_TOKEN=<token> ./gradlew assembleDebug.
Never write the token into a file in the repo. Prefer IONIC_TOKEN set from a secret store, because a typed -PionicToken stays in the shell history. Do not run the preload with --info, because it logs the command line. To drop a preloaded bundle, run ./gradlew cleanMwaAssets.
- Creating a
Portalwith aninitialContext - Enabling Live Updates (fetching updated MWA bundles without releasing a new app version)
- Adding a
PortalViewto the layout to display the Ionic screen
The project demonstrates how to:
- Subscribe to events sent from the web app (e.g.,
dismiss)
- Run
npm install <plugin>. - In
settings.gradle, add the module to theincludeline and setproject(':<name>').projectDir = new File('node_modules/<plugin>/android'). - In
app/build.gradle, addimplementation project(':<name>'). - Add the plugin class to
setPlugins(...)inIonicSampleActivity.kt.
A plugin from Maven instead (like Preferences) needs exclude group: 'com.capacitorjs', module: 'core' on its line, so the app keeps one Capacitor core.
This project demonstrates the full integration cycle of MWA:
preloading the bundle → rendering it on screen → handling event communication between Android and Ionic.