July 12, 2021
So what exactly is Capacitor? According to documentation
Capacitor is a cross-platform app runtime that makes it easy to build web apps that run natively on iOS, Android, Electron, and the web. We call these apps “Native Progressive Web Apps” and they represent the next evolution beyond Hybrid apps.
So today we will build our android or ios app using the existing react app.
{
"appId": "io.ionic.nameofyourapp",
"appName": "nameofyourapp",
"bundledWebRuntime": false,
"npmClient": "npm",
"webDir": "build",
"cordova": {}
}
{
"name": "nameofyourapp",
"integrations": {
"capacitor": {}
},
"type": "react"
}
Note: replace nameofyourapp in both files with the name of your app.
npm run build
Note: this will create the build folder in your root porject and the name of the folder should match the webDir name inside capacitor.config.json file
npm install -g @ionic/cli
npm install @capacitor/core --save
ionic capacitor add android
npx cap open android
Wait some time and then it will ask you to update the Gradle. Just update the Gradle to the latest version and run the project in the emulator. You can also connect your mobile to run the project live on your mobile phone.
ionic capacitor add ios
This will install all the required dependencies and ios folder to your project.
npx cap open ios