Cordova Command-Line Interface (CLI) Reference Manual

This chapter serves as a reference manual. You don’t need to learn everything at once; simply refer to it as needed.

CLI Syntax

cordova <command> [options] -- [platform-specific arguments]Code language: CSS (css)

Global Command List

Can be executed without navigating into a Cordova project directory

CommandDescription
createCreate a new project
helpShow documentation for a specified command
configSet, query, delete, edit and list global Cordova configuration entries

Project Command List

Must run inside the root directory of a valid Cordova project

CommandDescription
infoPrint project environment details
requirementsDetect and output all required dependencies for target platforms
platformManage project platforms (Android/iOS/Browser, etc.)
pluginManage project plugins
prepareCopy asset files to platform directories to get ready for compilation
compileCompile the project for specified platforms
buildBuild application (equivalent to prepare + compile)
cleanClear cached build artifacts generated by platform compilation
runLaunch application (internally runs prepare + compile + deployment)
serveStart local web server for web asset preview (triggers prepare internally)

Common Options (Supported by all CLI commands)

ArgumentDescription
-d / –verboseOutput detailed logs. If invoking cordova-cli within Node code, listen for log and warn events to capture logs: cordova.on('log', ()=>{})
-v / –versionPrint current Cordova CLI version
–nohooksPrevent hook script execution; supports regular expression filtering for hooks

Platform-Specific Arguments Explained

Certain commands support custom platform arguments (platformOpts).
Use -- as separator: parameters before -- are parsed by Cordova CLI, and all arguments after -- are passed directly to the native platform build tools.


CLI Usage Examples

Demonstration of complete workflow:

  1. Create project
  2. Install camera plugin
  3. Add Android platform
  4. Compile and run on Android
  5. Generate release build with Android signing parameters
# Create project
cordova create myApp com.foxdevelop.myApp myApp
cd myApp

# Add camera plugin
cordova plugin add cordova-plugin-camera

# Add Android platform
cordova platform add android

# Check Android build environment dependencies
cordova requirements android

# Compile Android with verbose logs
cordova build android --verbose

# Launch app on device/emulator
cordova run android

# Release build with signing arguments
cordova build android --release -- --keystore="..\android.keystore" --storePassword=android --alias=mykeyCode language: PHP (php)

Detailed Command Reference

cordova create

Generate directory structure for Cordova project.
Syntax:

cordova create path [packageId [appName]] [options]Code language: CSS (css)

Parameters

ValueDescription
pathProject folder (folder must not exist beforehand; CLI creates it automatically)
idPackage identifier, default: org.apache.cordova.hellocordova
Reverse domain format, matches widget id inside config.xml; used to generate Java package names, configure appropriately
nameApplication display name, default: Hello Cordova
Maps to name field in config.xml and becomes native project class name

Options

  • --template: Create project using custom template from local path, NPM or GitHub
cordova create myapp com.mycompany.myteam.myapp MyAppCode language: CSS (css)

cordova platform

Manage platforms: add, remove, update and list platforms. Adding or removing platforms modifies the project platforms directory.

cordova {platform | platforms} [
    add <platform-spec> [...] {--save | link=<path> } |
    {remove | rm} platform [...] {--save}|
    {list | ls}  |
    update ]Code language: HTML, XML (xml)

Subcommands & Parameters

SubcommandParameterDescription
add <platform-spec>Add platform
–nosaveDo not write platform information into config.xml / package.json after installation
–link=Create symbolic link instead of copying files when using local platform source (for platform development debugging)
remove <platform>Delete platform
–nosaveRemove platform without erasing records inside config.xml / package.json
update <platform>Upgrade platform version
–saveUpdate recorded platform version inside config.xml
list / lsList all installed and available platforms

Platform Spec Format <platform-spec>

platform[@version] | local path | Git url[#branch/tag/commit]Code language: PHP (php)
  • platform: platform name android / ios / browser / electron
  • version: Semantic version semver, example ^13.0.0
  • path: Local platform source directory / tar archive
  • url: Git repository address
  • commit-ish: Specify branch, tag, commit hash; defaults to master if omitted

Supported Platforms

android, browser, electron, ios

# Add Android and iOS and save records to config
cordova platform add android ios

# Add Android platform with specified version
cordova platform add android@^13.0.0

# Install platform from Git repository with specific tag
cordova platform add https://github.com/myfork/cordova-android.git#13.0.0

# Install platform from local folder
cordova platform add ../android

# Remove Android platform
cordova platform rm android

# View all platforms
cordova platform lsCode language: PHP (php)

cordova plugin

Manage project plugins

cordova {plugin | plugins} [
    add <plugin-spec> [..] {--searchpath=<dir> | --noregistry | --link | --save | --force} |
    {remove | rm} {<pluginId> | <name>} --save |
    {list | ls}
]Code language: HTML, XML (xml)

Subcommand Parameters

SubcommandParameterDescription
add <plugin-spec>Add plugin
–searchpath <dir>Search local directories first for plugins; path separator Windows ;, Linux/Mac :
–noregistryAvoid fetching plugins from official npm registry
–linkCreate symbolic link when installing local plugin folder (for plugin debugging)
–nosaveSkip writing records into config.xml / package.json
–forceForce overwrite conflicting files (added in version 6.1)
removeRemove plugin
–nosaveDelete plugin but keep records in configuration files
list / lsList installed plugins

Plugin Spec Format <plugin-spec>

[@scope/]pluginId[@version] | local directory | Git url[#commit][:subfolder]Code language: PHP (php)

Plugin Resolution Priority (Highest → Lowest)

  1. Explicit plugin and version specified via command line
  2. Plugin information stored in config.xml / package.json
  3. Latest npm version compatible with current project (plugin package.json declares cordova dependency)
  4. Latest available plugin version on npm
# Install camera and file plugin, search ../plugins first
cordova plugin add cordova-plugin-camera cordova-plugin-file --searchpath ../plugins

# Install specific plugin version
cordova plugin add cordova-plugin-camera@^2.0.0

# Install plugin from local folder
cordova plugin add ../cordova-plugin-camera

# Remove plugin
cordova plugin rm cordova-plugin-camera

# List plugins
cordova plugin lsCode language: PHP (php)

Plugin Conflict Notes

Some plugins modify native configuration files via edit-config inside plugin.xml.
Conflicts occur when multiple plugins edit the same XML node; CLI blocks installation by default.
Solutions:

  1. Modify plugin plugin.xml to avoid editing identical nodes (Recommended)
  2. Force installation using --force (⚠️ Risk: Overwrites modifications from other plugins and may break them)

cordova prepare

Synchronize config.xml settings to native manifest files for each platform; copy icons, splash screens and plugin assets; prepare project to satisfy native SDK build requirements.

cordova prepare [platformNames...]Code language: CSS (css)

All platforms are processed if no platform specified.

cordova compile

Run compilation only, prepare will not execute. Usually use build directly; mainly used for hook extension scenarios.

cordova compile [platforms...]
    [--debug | --release]
    [--device | --emulator | --target=<name>]
    [--buildConfig=<file>]
    [-- platform arguments]Code language: CSS (css)

cordova build

Equivalent to prepare + compile, builds application packages.

cordova build [platforms...]
    [--debug | --release]
    [--device | --emulator]
    [--buildConfig=<configFile>]
    [-- platform arguments]Code language: CSS (css)
ParameterDescription
–debugDebug build package
–releaseRelease production package
–deviceBuild package targeting physical devices
–emulatorBuild package for emulator architecture
–buildConfigSpecify build configuration file, defaults to build.json in project root, commonly used for signing setup
cordova build android --release --buildConfig=build.json
cordova build android --release -- --keystore="app.keystore" --alias=key0Code language: JavaScript (javascript)

cordova run

Execute prepare → build → deploy application to device/emulator and launch it.

cordova run [platforms...]
    [--list | --debug | --release]
    [--noprepare]
    [--nobuild]
    [--device | --emulator | --target=<name>]
    [--buildConfig=<file>]
    [-- platform arguments]Code language: CSS (css)
ParameterDescription
–listList all connected physical devices and emulators
–noprepareSkip prepare step (6.2+)
–nobuildSkip compilation, deploy existing built package directly
–targetSelect specific emulator/device name, query names using --list

Examples:

# List available devices
cordova run android --list
# Run on specified emulator
cordova run android --target=Nexus_5_API_23_x86
# Run without rebuilding
cordova run android --nobuildCode language: PHP (php)

cordova emulate

Alias for cordova run --emulator, launches app only inside emulator.

cordova clean

Remove compiled build artifacts for each platform

cordova clean android

cordova requirements

Check all environment dependencies required by platforms (JDK, Android SDK, Xcode, etc.)

cordova requirements android

Returns exit code 0 when all dependencies satisfied, non-zero value if missing dependencies. Widely used for automated build environment validation.

cordova info

Output full environment, platform and plugin information; required when submitting bug reports.

cordova info

cordova serve

Start local web server to preview www web assets, default port 8000

cordova serve 8080
# Access URL: http://127.0.0.1:8080/android/wwwCode language: PHP (php)

cordova help

View command documentation

cordova help build
cordova build -h

cordova config

Manage global Cordova configurations

cordova config ls                # List all configurations
cordova config set save-exact true
cordova config get save-exact
cordova config delete save-exact
cordova config editCode language: PHP (php)

Cordova Command-Line Interface (CLI) Reference Manual

Leave a Reply

Your email address will not be published. Required fields are marked *