Skip to the content.

CapacitorJS (capacitorjs)

Capacitor is a cross-platform native runtime for building Web Native apps. It allows you to create a single web-based application that runs natively on iOS, Android, and the Web (as a PWA).

Introduction

Capacitor (capacitorjs) acts as a “bridge” or “native shell” for your web application. Unlike Cordova, which used a set of custom-built plugins and a rigid CLI, Capacitor treats your web app as a first-class citizen. It provides a standard set of APIs that work across all platforms and allows you to easily drop down into native code (Swift or Kotlin) when needed.

For SMI projects, Capacitor is the recommended way to “native-ify” a PWA when browser-level limitations (like hardware access or iOS backgrounding) are encountered.

Installation

Prerequisites

Adding Capacitor to your Project

  1. Initialize Capacitor in your web project root:
    npm install @capacitor/core @capacitor/cli
    npx cap init
    

    Follow the prompts to enter your App Name and Package ID (e.g., info.setmy.app).

  2. Build your web project (e.g., npm run build or ng build). Ensure your build output directory matches the webDir in capacitor.config.ts (usually dist or www).

  3. Install and add native platforms:
    npm install @capacitor/ios @capacitor/android
    npx cap add ios
    npx cap add android
    

Preparations for Developers

Synchronization

Whenever you make changes to your web code and build it, you must sync those changes to the native platforms:

npx cap copy

If you install new Capacitor plugins, use sync instead:

npx cap sync

Running the App

Open the native IDEs to run the app on simulators or real devices:

npx cap open ios
npx cap open android

Native Bridge & Plugins

Preparation for Release and Live

General

iOS Release

  1. In Xcode, set the Bundle Identifier and Version.
  2. Configure Code Signing with a valid Apple Developer certificate.
  3. Perform an Archive and upload to App Store Connect / TestFlight.

Android Release

  1. In Android Studio, generate a Signed App Bundle (AAB) or APK.
  2. Use ProGuard if needed to minify and obfuscate your web assets (though web code is usually already minified).
  3. Upload the AAB to the Google Play Console.

Tips and Tricks

Debugging

Performance

Common Issues

See also