LinuxCommandLibrary

cordova

Build cross-platform mobile applications

TLDR

Create a Cordova project

$ cordova create [path/to/directory] [package] [project_name]
copy

Display the current workspace status
$ cordova info
copy

Add a Cordova platform
$ cordova platform add [platform]
copy

Remove a Cordova platform
$ cordova platform remove [platform]
copy

Add a Cordova plugin
$ cordova plugin add [pluginid]
copy

Remove a Cordova plugin
$ cordova plugin remove [pluginid]
copy

SYNOPSIS

cordova <command> [options]
cordova <command> --help

Common commands:
cordova create <path> [id] [name]
cordova platform add <platform_name>
cordova build [platform_name] [--release|--debug]
cordova emulate <platform_name>
cordova run <platform_name>
cordova plugin add <plugin_id>

PARAMETERS

--version
    Displays the installed Cordova CLI version number.

--help
    Displays general help or detailed help for a specific command.

create <path> [id] [name]
    Creates a new Cordova project in the specified directory.
<path>: Required. The target directory for the new project.
[id]: Optional. A reverse-domain-style identifier for the application (e.g., com.example.myapp).
[name]: Optional. The human-readable display name for the application.

platform add|rm <platform_name>
    Adds or removes a target mobile platform to or from your project.
<platform_name>: Required. The name of the platform (e.g., android, ios, browser).

build|run|emulate [platform_name] [--release|--debug|--device|--emulator]
    Builds, runs, or emulates the application on a specific or all added platforms.
[platform_name]: Optional. Specifies a particular platform to target; if omitted, all added platforms are targeted.
--release: Optional. Builds the application for release (signed and optimized).
--debug: Optional. Builds the application for debugging (unsigned and debuggable).
--device: Optional. Deploys the application to a connected physical device.
--emulator: Optional. Deploys the application to an emulator or simulator.

plugin add|rm <plugin_id>
    Adds or removes a plugin to or from the project.
<plugin_id>: Required. The identifier of the plugin (e.g., cordova-plugin-camera), a local path, or a Git URL.

DESCRIPTION

The cordova command-line interface (CLI) is a powerful tool for Apache Cordova, an open-source framework that enables developers to build hybrid mobile applications using standard web technologies like HTML, CSS, and JavaScript. It provides a comprehensive set of commands to create, configure, build, run, and manage Cordova projects.

The CLI acts as a crucial bridge, allowing web assets (your application's code) to be packaged into native application wrappers for various mobile operating systems, such as Android, iOS, and Windows. This capability allows developers to write their application code once and deploy it across multiple platforms, significantly reducing development time and effort compared to building fully native applications for each platform individually. Beyond core project management, the cordova command facilitates the integration of native device functionalities through plugins and manages platform-specific builds and emulations.

CAVEATS

The cordova command itself requires Node.js and npm (Node Package Manager) to be installed and configured on the system. Furthermore, building and running applications for specific mobile platforms (e.g., Android, iOS) necessitates additional platform-specific SDKs and tools (e.g., Android SDK, Xcode for iOS) to be properly installed and their environment variables (like ANDROID_HOME) configured. Development for iOS is generally restricted to macOS environments due to Apple's licensing and tooling requirements. Hybrid applications may exhibit performance limitations compared to fully native apps, particularly in graphics-intensive scenarios. Debugging can also be more complex due to the layered nature of hybrid development.

PLUGINS

Cordova's core functionality is extended through plugins. Plugins provide JavaScript APIs that allow your web application to access native device capabilities like the camera, GPS, contacts, accelerometer, and file system, which are not directly accessible from standard web views. Developers can utilize official Apache plugins, community-contributed plugins, or even develop their own custom plugins to integrate specific native features.

PLATFORMS

While Cordova abstracts away much of the platform-specific code, projects still target individual mobile platforms. The cordova CLI manages the platform-specific project structure within your main Cordova project directory. Each platform (e.g., Android, iOS, Browser) maintains its own native project files, which the CLI generates and updates based on your web assets and configuration.

HOOKS

The cordova CLI supports hooks, which are custom scripts that can be executed automatically before or after specific Cordova commands (e.g., before_build, after_prepare, before_plugin_add). Hooks provide a powerful mechanism for automating custom tasks, such as modifying configuration files, running tests, or performing code transformations, throughout the development and build workflow.

HISTORY

Apache Cordova originated as PhoneGap, an innovative open-source framework developed by Nitobi. In 2011, Adobe acquired Nitobi and subsequently open-sourced PhoneGap's core, contributing it to the Apache Software Foundation under the name Apache Cordova. Adobe continues to offer its commercial version under the PhoneGap brand, while the open-source project is maintained by the Apache Cordova community. This pivotal move democratized cross-platform mobile development using ubiquitous web technologies, enabling developers to target multiple mobile operating systems without the need to learn platform-specific languages like Java/Kotlin for Android or Objective-C/Swift for iOS. Its ongoing development has focused on enhancing performance, expanding plugin capabilities, and adapting to the evolving features and requirements of mobile operating systems.

SEE ALSO

npm(1), node(1), ionic(1), react-native(1), flutter(1)

Copied to clipboard