Cordova

From G1Joshi/Agent-Skills · View interactive version

Cordova is an AI agent skill from the GitHub repository G1Joshi/Agent-Skills. Expert Apache Cordova assistance covering hybrid WebView architectures, config.xml configuration, custom plugin authoring, and platform CLI tooling. Use when maintaining or migrating legacy Cordova apps, managing device hardware plugins, or building cross-platform web shells.

How to use this skill

Skill file

Cordova

Apache Cordova (formerly PhoneGap) wraps HTML/CSS/JS apps in a native WebView container. While largely superseded by Capacitor and React Native, it remains active (CLI 13.x) for specific legacy use cases.

When to Use

Quick Start

npm install -g cordova
cordova create hello com.example.hello HelloWorld
cd hello
cordova platform add android
cordova platform add ios
cordova run android

Core Concepts

Declarative config.xml Schema

The central manifest orchestrates app metadata, permissions, preferences, and plugin parameters across platforms:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.logistics" version="2.4.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>LogisticsTracker</name>
    <description>Enterprise warehouse scanning application.</description>
    <preference name="Orientation" value="portrait" />
    <preference name="DisallowOverscroll" value="true" />
    <platform name="android">
        <preference name="AndroidXEnabled" value="true" />
    </platform>
</widget>

deviceready Lifecycle Event

Cordova requires waiting for native bridge initialization before invoking any hardware plugin APIs:

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
  console.log("Running cordova-" + cordova.platformId + "@" + cordova.version);
  // Safe to invoke native plugins
  navigator.splashscreen.hide();
}

Native Plugin Hook Architecture

Hooks execute arbitrary Node.js scripts during the build lifecycle (e.g. copying release Google Services JSON, injecting Gradle properties):

// hooks/after_prepare.js
const fs = require("fs");
const path = require("path");

module.exports = function (context) {
  const root = context.opts.projectRoot;
  const src = path.join(root, "config/google-services.json");
  const dest = path.join(root, "platforms/android/app/google-services.json");
  if (fs.existsSync(src)) {
    fs.copyFileSync(src, dest);
    console.log("Injected google-services.json into Android platform.");
  }
};

Common Patterns

Modernizing Legacy Webviews via Capacitor Migration

Problem: Deprecated Cordova build tooling causing build breaks with modern mobile OS toolchains.

Solution:

Migrate web assets and plugins to Capacitor as a modern drop-in runner:

npm install @capacitor/cli @capacitor/core
npx cap init
# Capacitor automatically reads config.xml and supports most Cordova plugins

Best Practices

Do:

Don't:

Troubleshooting

| Error | Cause | Solution |

| :----------------------- | :------------------------------------------- | :------------------------------------------------------------ |

| deviceready not firing | JS error before event or missing cordova.js. | Check console; ensure cordova.js is included in index.html. |

| White Screen | CSP blocking scripts or syntax error. | Check Content-Security-Policy and remote debugging. |

| Gradle build failed | Java/Gradle version mismatch. | Check cordova requirements android output. |

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.