Skip to main content

Someone wanted to learn this too, so Grasp built them a personal learning path.

You can keep exploring this one or create your own

Implementing OTA Updates with Capacitor-Updater

Now that you have a firm grasp of the App Store and Play Store policies governing Over-the-Air (OTA) updates, we can move from theory to practice. In the previous lesson, we established the critical boundary: OTA updates can change the web layer of your application, but not the native layer. This understanding is the foundation for implementing this feature safely and effectively.

This lesson will guide you through the process of installing and configuring a third-party OTA service. Your goal is to integrate a service that will manage and deliver web updates to your users' devices. We will use Capgo, a popular service with a dedicated Capacitor plugin, @capgo/capacitor-updater. We will focus on getting the service set up, installing the necessary tools, and configuring your project. By the end of this lesson, your app will be ready to receive its first OTA update.

1. Choosing and Setting Up an OTA Service

Several services provide OTA updates for Capacitor, including Ionic's Appflow and Capawesome's solution. For this course, we will use Capgo because it offers a generous free tier for getting started, excellent documentation, and a powerful command-line interface (CLI) that aligns well with your development workflow.

The Capgo system consists of two main parts:

  • The Capgo Cloud Platform: A web dashboard and backend service where you will create your app, manage update channels, and upload your web bundles.
  • The @capgo/capacitor-updater Plugin: A Capacitor plugin you install in your project. Its job is to communicate with the Capgo cloud, check for new updates, download them, and apply them.

Our first step is to set up your presence on the Capgo platform.

capgo-live-updates | Skills Marketplace · LobeHub

This guide provides a concise walkthrough of the initial setup process for Capgo, including installing its CLI using bun, which matches your preferred tooling.

Follow the first three steps in this guide: Navigate to the Capgo website and create a free account. Next, install the Capgo CLI globally. You should use the provided bun command: bun add -g @capgo/cli. Finally, log in to your account from your terminal by running bunx @capgo/cli login. This command will open a browser window for authentication.

With the CLI installed and authenticated, you now have the primary tool for interacting with the Capgo service from your command line.

2. Integrating Capgo into Your Turborepo Project

The Capgo CLI provides a convenient init command to bootstrap the integration process. This command will inspect your project, identify it as a Capacitor application, create a corresponding app on your Capgo dashboard, and attempt to install and configure the client plugin.

Given your Turborepo setup, it's important to run this command from the correct directory. Your native projects are housed in the dedicated mobile location (e.g., apps/mobile), which is where your capacitor.config.ts file resides. This is the context Capacitor commands should run in.

In your terminal, navigate to your mobile app's directory and run the initialization command.

cd apps/mobile
bunx @capgo/cli init

The CLI will prompt you to name your application. This name will appear on your Capgo dashboard. Once the command completes, it will have performed several key actions:

  1. Created an App in Capgo: A new application record is now visible in your Capgo web dashboard.
  2. Installed the Plugin: It should have added @capgo/capacitor-updater as a dependency to your web app's package.json.
  3. Configured Capacitor: It has modified your capacitor.config.ts file to include the necessary plugin configuration.

Let's verify these changes and understand the configuration.

3. Verifying and Understanding the Configuration

The init command automated the setup, but as an experienced developer, it's crucial to understand what it did.

First, check the package.json of your React SPA (e.g., in apps/web/package.json). You should see @capgo/capacitor-updater listed in the dependencies.

Second, and most importantly, inspect your apps/mobile/capacitor.config.ts file. You will find a new entry under the plugins key. It should look something like this:

// apps/mobile/capacitor.config.ts
import type { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  // ... other configs like appId, appName, webDir
  plugins: {
    CapacitorUpdater: {
      autoUpdate: true,
    },
  },
};

export default config;

This configuration tells the updater plugin to automatically check for, download, and apply new updates when the app starts. For a deeper look into the available configuration options, you can consult the official documentation.

Getting Started - Capacitor Plugin Docs & Examples | Capgo

The official documentation provides a comprehensive list of all configuration options for the plugin.

First, review the Auto-Update Mode section to confirm the basic structure. Then, scan the full list of options to see what's available. Pay attention to defaultChannel, as we will use this concept in the next lesson to manage different release tracks like staging and production.

One of the great advantages of this plugin is its simplicity regarding native project setup. As the documentation confirms, no additional manual changes are required for the iOS or Android native projects. The cap sync command handles everything.

4. Finalizing the Integration with cap sync

The init command likely ran capacitor sync for you, but it's good practice to run it again manually to ensure all native dependencies are correctly linked. This command is the glue that connects your web code and plugins to the native iOS and Android shells.

From your apps/mobile directory, run the sync command:

bunx cap sync

This command performs two key actions in this context:

  1. It copies your web app's build artifacts from the webDir specified in capacitor.config.ts into the native projects.
  2. It reads the list of installed Capacitor plugins (including our new @capgo/capacitor-updater) and automatically applies the necessary modifications to your native iOS (Podfile) and Android (build.gradle) projects.

With this step complete, your native projects are now fully aware of the updater plugin and contain the necessary Swift and Kotlin code to handle the update process.

Conclusion

In this lesson, you have successfully integrated a powerful Over-the-Air update service into your application. You are now set up for a much more agile release process for your web-based features and fixes.

Let's summarize the key takeaways:

  • Service Setup: You created an account with the Capgo cloud service and installed its command-line tool, the capgo/cli.
  • Project Initialization: You used bunx @capgo/cli init within your Turborepo's mobile package to automatically install the @capgo/capacitor-updater plugin and configure it in capacitor.config.ts.
  • Auto-Update Enabled: The default configuration enables autoUpdate, meaning the plugin will manage the update lifecycle automatically on app start.
  • Native Integration via Sync: You confirmed that bunx cap sync is the essential command that links the plugin's native components into your iOS and Android projects.

Your application is now technically capable of receiving updates. However, we haven't actually sent one yet. In the next lesson, we will build upon this foundation. You will learn how to set up an OTA channel, create and publish a new web bundle from your Turborepo, and witness your first live update in action.

Can't find a good explanation? Sign up and we'll make it for you

Sign up