We strongly recommend to use Capacitor. However, if you are not ready yet, don't worry, you can still use Cordova.
The Capacitor workflow involves a few consistent tasks:
​Copy your Web Assets​
​Open your Native IDE​
​Periodic Maintenance​
This app has an iOS folder which contains the iOS native app. Read how to build this app for iOS.
This app has an Android folder which contains the Android native app. Read how to build this app for Android.
Follow the steps from the Capacitor Workflow.
You must build your Ionic project at least once before adding any native platforms.
ionic build
This creates the www
folder that Capacitor has been automatically configured to use as the webDir
in capacitor.config.json.
Because our project uses SSR, we don’t have www
folder. We instead have to use dist/app/browser
and change it in capacitor.config.json
Both android and ios folders at the root of the project are created. These are entirely separate native project artifacts that should be considered part of your Ionic app (i.e., check them into source control, edit them in their own IDEs, etc.).
When you are ready to run your app natively on a device or in a simulator, copy your built web assets using:
npx cap copy
Capacitor uses the Native IDEs to build, simulate, and run your app. To open one, run:
npx cap open
In some cases, the Capacitor app needs to be updated, such as when installing new plugins.
To install new plugins (including Cordova ones), run:
npm install really-cool-pluginnpx cap update
To check if there are any new updates to Capacitor itself, run npx cap doctor
to print out the current installed dependencies as well view the latest available.
To update Capacitor Core and CLI:
npm install @capacitor/cli@latestnpm install @capacitor/core@latest
To update any or all of the platforms you are using:
npm install @capacitor/ios@latestnpm install @capacitor/android@latest
See how to do this in the following video.
We use and strongly recommend using Capacitor, the developer experience is SO MUCH better than it was with Cordova. However, in this section, we will show you how to remove Capacitor and add Cordova if you are not yet ready to use it.
Delete ios, android and .gradle folders
Delete capacitor.config.json
Run: ionic integrations disable capacitor
Run: ionic cordova platform add ios
Run: ionic cordova platform add android
You will have to change the Capacitor plugins for Ionic Native plugins.
Install Ionic Native by running:
npm install @ionic-native/core @ionic-native/status-bar @ionic-native/splash-screen --save
Go to app.component.ts
and do the following:
Remove:
import { Plugins } from '@capacitor/core';const { SplashScreen } = Plugins;
Add:
import { SplashScreen } from '@ionic-native/splash-screen/ngx';import { StatusBar } from '@ionic-native/status-bar/ngx';import { Platform } from '@ionic/angular';
Change the initializeApp()
method for the following code:
initializeApp() {this.platform.ready().then(() => {this.statusBar.styleDefault();this.splashScreen.hide();});}
Add the following parameters to the constructor:
constructor(...,private platform: Platform,private splashScreen: SplashScreen,private statusBar: StatusBar)
Now go to app.module.ts and add the following:
import { SplashScreen } from '@ionic-native/splash-screen/ngx';import { StatusBar } from '@ionic-native/status-bar/ngx';
Then add them as providers of the module:
providers: [StatusBar,SplashScreen,...],
Now if you run ionic serve everything should work fine.
We use Share and Geolocation plugins from Capacitor. If you want those features to work in your Cordova app, you need to change the implementation using the respective Ionic Native plugins.
Now you can safely remove the Capacitor dependencies from your package.json.
npm uninstall --save @capacitor/androidnpm uninstall --save @capacitor/clinpm uninstall --save @capacitor/corenpm uninstall --save @capacitor/ios