### lib-file Example for JAR Installation
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/plugin_ref/spec.md
This XML shows how to use the lib-file element to install a .jar file into the project's libs directory. The 'src' attribute specifies the location of the .jar file relative to the plugin.xml.
```xml
```
--------------------------------
### Plugin Info Tag Example
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/plugin_ref/spec.md
Use the 'info' tag to provide users with additional instructions or information that cannot be automated by the CLI, such as manual SDK setup or configuration steps.
```xml
You need to install __Google Play Services__ from the `Android Extras` section using the Android SDK manager (run `android`).
You need to add the following line to the `local.properties`:
android.library.reference.1=PATH_TO_ANDROID_SDK/sdk/extras/google/google_play_services/libproject/google-play-services_lib
```
--------------------------------
### Install Cordova Media Plugin
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/plugin_ref/plugman.md
Use this command to install the media plugin for a specified platform and project directory.
```bash
plugman install --platform --project --plugin cordova-plugin-media
```
--------------------------------
### Install Cordova CLI on Windows
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/guide/cli/installation.md
Use this command to install the Cordova CLI globally on Windows systems. The `-g` flag ensures a global installation.
```bash
C:\>npm install -g cordova
```
--------------------------------
### Install Cordova CLI
Source: https://github.com/apache/cordova-docs/blob/master/www/index.html
Installs the Cordova command-line interface globally using npm. Ensure Node.js is installed first.
```bash
$ npm install -g cordova
```
--------------------------------
### Initialize and Install Ruby DevKit on Windows
Source: https://github.com/apache/cordova-docs/blob/master/doc/installing-a-development-environment.md
Initializes and installs the Ruby Development Kit. This is a multi-step process requiring command prompt execution.
```bash
cd C:\Ruby22DevKit
ruby dk.rb init
ruby dk.rb install
```
--------------------------------
### Example Android SDK Paths on Windows
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/guide/platforms/android/index.md
Example paths for the Android SDK on Windows. These should be added to the system's PATH environment variable.
```txt
C:\Users\[your user]\AppData\Local\Android\Sdk\platform-tools
C:\Users\[your user]\AppData\Local\Android\Sdk\cmdline-tools\latest\bin
C:\Users\[your user]\AppData\Local\Android\Sdk\build-tools
C:\Users\[your user]\AppData\Local\Android\Sdk\emulator
```
--------------------------------
### Install Plugman Globally
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/plugin_ref/plugman.md
Install plugman globally using npm. Ensure Node.js is installed and that the npm directory is in your system's PATH.
```bash
$ npm install -g plugman
```
--------------------------------
### Install Cordova Camera Plugin
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/plugin_ref/plugman.md
Use this command to install the camera plugin for a specified platform and project directory.
```bash
plugman install --platform --project --plugin cordova-plugin-camera
```
--------------------------------
### Install Cordova File Plugin
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/plugin_ref/plugman.md
Use this command to install the file plugin for a specified platform and project directory.
```bash
plugman install --platform --project --plugin cordova-plugin-file
```
--------------------------------
### Install Cordova Device Plugin
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/plugin_ref/plugman.md
Use this command to install the device plugin for a specified platform and project directory.
```bash
plugman install --platform --project --plugin cordova-plugin-device
```
--------------------------------
### Install Cordova Media Capture Plugin
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/plugin_ref/plugman.md
Use this command to install the media capture plugin for a specified platform and project directory.
```bash
plugman install --platform --project --plugin cordova-plugin-media-capture
```
--------------------------------
### Install Cordova Vibration Plugin
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/plugin_ref/plugman.md
Use this command to install the vibration plugin for a specified platform and project directory.
```bash
plugman install --platform --project --plugin cordova-plugin-vibration
```
--------------------------------
### Install Cordova Electron Platform
Source: https://github.com/apache/cordova-docs/blob/master/www/_posts/2019-08-27-cordova-electron-release-1.1.1.md
Use this command to install Cordova Electron version 1.1.1 for a new project.
```bash
cordova platform add electron@1.1.1
```
--------------------------------
### Install ios-deploy via Homebrew
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/guide/platforms/ios/index.md
Install the ios-deploy tool using Homebrew to enable launching iOS apps on devices from the command line.
```zsh
brew install ios-deploy
```
--------------------------------
### Install Cordova Network Information Plugin
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/plugin_ref/plugman.md
Use this command to install the network information plugin for a specified platform and project directory.
```bash
plugman install --platform --project --plugin cordova-plugin-network-information
```
--------------------------------
### Install Cordova Console Plugin
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/plugin_ref/plugman.md
Use this command to install the console plugin for a specified platform and project directory.
```bash
plugman install --platform --project --plugin cordova-plugin-console
```
--------------------------------
### Install Cordova Android Platform
Source: https://github.com/apache/cordova-docs/blob/master/www/_posts/2022-04-15-cordova-android-release-10.1.2.md
Use this command to install Cordova Android 10.1.2 on a new or existing project.
```bash
cordova platform add android@10.1.2
```
--------------------------------
### Install Plugin from Git URL with Link
Source: https://github.com/apache/cordova-docs/blob/master/www/_posts/2015-01-09-tools-release.md
This change ensures that plugin installation from a git URL with the `--link` option does not fail.
```bash
cordova plugin add --link git+https://github.com/user/repo.git
```
--------------------------------
### Install Cordova Simulate Globally
Source: https://github.com/apache/cordova-docs/blob/master/www/_posts/2018-02-02-cordova-simulate.md
Install Cordova Simulate globally using npm to make the 'simulate' command available in your terminal.
```bash
npm install -g cordova-simulate
```
--------------------------------
### Serve the Website Locally
Source: https://github.com/apache/cordova-docs/blob/master/doc/developing-the-website.md
Builds the site and starts a local server for live development. Add `--nodocs` to exclude documentation from the build.
```bash
node_modules/.bin/gulp serve
```
```bash
node_modules/.bin/gulp serve --nodocs
```
--------------------------------
### Example build-extras.gradle configuration
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/guide/platforms/android/index.md
This example demonstrates how to set custom properties, configure Android defaults, add dependencies, and define post-build actions using build-extras.gradle.
```groovy
// This file is included at the beginning of `build.gradle`
// special properties (see `build.gradle`) can be set and overwrite the defaults
ext.cdvDebugSigningPropertiesFile = '../../android-debug-keys.properties'
// normal `build.gradle` configuration can happen
android {
defaultConfig {
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
}
dependencies {
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2',
{
exclude group: 'com.android.support', module: 'support-annotations'
}
}
// When set, this function `ext.postBuildExtras` allows code to run at the end of `build.gradle`
ext.postBuildExtras = {
android.buildTypes.debug.applicationIdSuffix = '.debug'
}
```
--------------------------------
### Get Plugman Version
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/plugin_ref/plugman.md
Displays the currently installed version of Plugman using the --version or -v flag.
```bash
plugman -v
```
--------------------------------
### Sample config.xml Structure
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/config_ref/index.md
A basic example of a config.xml file, demonstrating essential elements like widget metadata, name, description, author, content source, security settings, and platform declarations.
```xml
HelloCordova
Sample Apache Cordova App
Apache Cordova Team
```
--------------------------------
### Get Cordova Version
Source: https://github.com/apache/cordova-docs/blob/master/www/contribute/nightly_builds.md
Retrieves the currently installed Cordova version. Useful for reporting issues with nightly builds.
```bash
cordova --version
```
--------------------------------
### Example Commit Message Prefixes
Source: https://github.com/apache/cordova-docs/blob/master/www/contribute/contribute_guidelines.md
Commit messages should start with the issue ID (prefixed with GH-) and the relevant platform, if applicable.
```git
GH-2345 android: Improved exec bridge by using strings instead of JSON
GH-3456 all: Fixed plugin loading paths that start with /
```
--------------------------------
### Add Platform and Plugin Example
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/platform_plugin_versioning_ref/index.md
This example demonstrates adding a specific version of the Android platform and the Cordova plugin for device. After execution, `package.json` will be updated with the dependencies and Cordova-specific metadata.
```bash
cordova platform add android@13.0.0
cordova plugin add cordova-plugin-device@3.0.0
```
--------------------------------
### Example PrivacyInfo.xcprivacy Contents
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/guide/platforms/ios/plugin.md
This XML snippet shows the basic structure for a PrivacyInfo.xcprivacy file, which is required by Apple for apps and SDKs starting May 1, 2024. Ensure all four keys are defined, even if empty.
```xml
NSPrivacyTracking
NSPrivacyTrackingDomains
NSPrivacyAccessedAPITypes
NSPrivacyCollectedDataTypes
```
--------------------------------
### Hook Execution Order Example (Build)
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/guide/appdev/hooks/index.md
Shows the fixed internal order of hook execution for a build command, including preparation and compilation stages.
```text
before_build
before_prepare
after_prepare
before_compile
after_compile
after_build
```
--------------------------------
### Install Ruby on Mac OS X
Source: https://github.com/apache/cordova-docs/blob/master/doc/installing-a-development-environment.md
Installs Ruby version 2.0 using Homebrew. Ensure Homebrew is installed first.
```bash
brew install ruby@2.0
```
--------------------------------
### Navigate to Project Directory
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/guide/cli/index.md
After creating the project, change into the project's directory to run subsequent commands.
```bash
cd hello
```
--------------------------------
### Install Cordova CLI Nightly Globally
Source: https://github.com/apache/cordova-docs/blob/master/www/contribute/nightly_builds.md
Installs the Cordova CLI nightly build globally on your system. This will replace any existing Cordova installation.
```zsh
npm install -g cordova@nightly
cordova
```
--------------------------------
### Install Cordova Electron Platform
Source: https://github.com/apache/cordova-docs/blob/master/www/_posts/2021-09-06-cordova-electron-release-3.0.0.md
Use this command to add the Electron platform to a Cordova project for the first time.
```bash
cordova platform add electron@3.0.0
```
--------------------------------
### Create App with Template and Fetch
Source: https://github.com/apache/cordova-docs/blob/master/www/_posts/2016-07-13-tools-release.md
Use the `--template` and `--fetch` flags with the `cordova create` command to create a new app from a template, enabling fetching of template dependencies.
```bash
cordova create Foo --template TEMPLATE_NAME --fetch
```
--------------------------------
### Install Ruby Gems Locally
Source: https://github.com/apache/cordova-docs/blob/master/doc/installing-a-development-environment.md
Installs Ruby dependencies using Bundler. Dependencies are installed locally in the 'ruby_modules' folder. May require 'sudo' or 'Run as Administrator' on some systems.
```bash
gem install bundler
bundle install --path ./ruby_modules
```
--------------------------------
### Electron Unique App and Installer Icons
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/config_ref/images.md
Specify distinct icons for the Electron application and its installer by using the 'target' attribute. The installer icon requires a minimum size of 512x512 pixels.
```xml
```
--------------------------------
### Build Production Website with Gulp
Source: https://github.com/apache/cordova-docs/blob/master/doc/deploying-the-website.md
Use this command to build the production version of the website. A 'build-prod' folder will be created containing the built site.
```bash
node_modules/.bin/gulp build --prod
```
--------------------------------
### Add Platform or Plugin from Local Directory
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/platform_plugin_versioning_ref/index.md
Installs platforms and plugins from a local directory path. Supports both Unix-like and Windows path formats.
```bash
cordova platform add ~/path/to/a/cordova-platform
cordova plugin add ~/path/to/a/cordova-plugin
cordova platform add C:/Path/to/a/cordova-platform
cordova plugin add C:/Path/to/a/cordova-plugin
```
--------------------------------
### Install cordova-plugin-inappbrowser
Source: https://github.com/apache/cordova-docs/blob/master/www/_posts/2015-12-14-plugins-release.md
Use this command to install the cordova-plugin-inappbrowser. It is backwards compatible with cordova-ios@3.
```bash
cordova plugin add cordova-plugin-inappbrowser --save
```
--------------------------------
### Install Specific Cordova Version
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/guide/cli/index.md
Use this command to install a particular version of the Cordova CLI.
```bash
npm install -g cordova@3.1.0-0.2.0
```
--------------------------------
### Hook Execution Order Example (Platform Add)
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/guide/appdev/hooks/index.md
Illustrates the serial execution order of hooks when adding a new platform. Application hooks from `config.xml` run before plugin hooks.
```text
before_platform_add
before_prepare
after_prepare
before_plugin_install
after_plugin_install
after_platform_add
```
--------------------------------
### Custom Scheme Example for Media Files
Source: https://github.com/apache/cordova-docs/blob/master/www/_posts/2023-09-12-camera-media-file-transfer-plugin-release.md
This example demonstrates how to load media files using a custom URL scheme, such as 'app://localhost/', to access files within the 'www' directory.
```javascript
app://localhost/file.mp4
```
--------------------------------
### List Installed Cordova Plugins
Source: https://github.com/apache/cordova-docs/blob/master/www/contribute/issues.md
Run this command in your project to list the versions of installed plugins.
```bash
cordova plugin ls
```
--------------------------------
### Install Cordova 3.2.0 RC1
Source: https://github.com/apache/cordova-docs/blob/master/www/_posts/2013-11-13-cordova-320rc1.md
Use this command to install Cordova version 3.2.0-rc.1 globally.
```bash
npm install -g cordova@3.2.0-rc.1
```
--------------------------------
### Upgrade Media and Media Capture Plugins
Source: https://github.com/apache/cordova-docs/blob/master/www/_posts/2022-05-30-media-plugin-6.0.0-media-capture-plugin-4.0.0-release.md
Use these commands to remove existing versions and install the new ones. Ensure you specify the exact versions for the upgrade.
```bash
cordova plugin remove cordova-plugin-media
cordova plugin add cordova-plugin-media@6.0.0
cordova plugin remove cordova-plugin-media-capture
cordova plugin add cordova-plugin-media-capture@4.0.0
```
--------------------------------
### Add Platform from Git Service Shorthand
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/platform_plugin_versioning_ref/index.md
Installs a platform from a Git repository using a shorthand format. Branches and tags can also be targeted.
```bash
cordova platform add github:apache/cordova-android
cordova platform add github:apache/cordova-android#feature-branch
cordova platform add github:apache/cordova-android#rel/13.0.0
```
--------------------------------
### Install rbenv and ruby-build
Source: https://github.com/apache/cordova-docs/blob/master/doc/installing-a-development-environment.md
Use Homebrew to install rbenv and ruby-build for managing Ruby versions.
```bash
brew install rbenv ruby-build
```
--------------------------------
### IndexedDB Usage Example
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/cordova/storage/storage.md
Demonstrates opening a database, handling success and error events, and creating an object store with indexes. This snippet is useful for initializing and setting up a new IndexedDB database.
```javascript
var db;
var databaseName = 'myDB';
var databaseVersion = 1;
var openRequest = window.indexedDB.open(databaseName, databaseVersion);
openRequest.onerror = function (event) {
console.log(openRequest.errorCode);
};
openRequest.onsuccess = function (event) {
// Database is open and initialized - we're good to proceed.
db = openRequest.result;
displayData();
};
openRequest.onupgradeneeded = function (event) {
// This is either a newly created database, or a new version number
// has been submitted to the open() call.
var db = event.target.result;
db.onerror = function () {
console.log(db.errorCode);
};
// Create an object store and indexes. A key is a data value used to organize
// and retrieve values in the object store. The keyPath option identifies where
// the key is stored. If a key path is specified, the store can only contain
// JavaScript objects, and each object stored must have a property with the
// same name as the key path (unless the autoIncrement option is true).
var store = db.createObjectStore('customers', { keyPath: 'customerId' });
// Define the indexes we want to use. Objects we add to the store don't need
// to contain these properties, but they will only appear in the specified
// index of they do.
//
// syntax: store.createIndex(indexName, keyPath[, parameters]);
//
// All these values could have duplicates, so set unique to false
store.createIndex('firstName', 'firstName', { unique: false });
store.createIndex('lastName', 'lastName', { unique: false });
store.createIndex('street', 'street', { unique: false });
store.createIndex('city', 'city', { unique: false });
store.createIndex('zipCode', 'zipCode', { unique: false });
store.createIndex('country', 'country', { unique: false });
// Once the store is created, populate it
store.transaction.oncomplete = function (event) {
// The transaction method takes an array of the names of object stores
// and indexes that will be in the scope of the transaction (or a single
// string to access a single object store). The transaction will be
// read-only unless the optional 'readwrite' parameter is specified.
// It returns a transaction object, which provides an objectStore method
// to access one of the object stores that are in the scope of this
//transaction.
var customerStore = db.transaction('customers', 'readwrite').objectStore('customers');
customers.forEach(function (customer) {
customerStore.add(customer);
});
};
};
function displayData() {
}
```
--------------------------------
### Install Cordova Splashscreen Plugin
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/plugin_ref/plugman.md
Use this command to install the splashscreen plugin for a specified platform and project directory.
```bash
plugman install --platform --project --plugin cordova-plugin-splashscreen
```
--------------------------------
### Create a Cordova Project
Source: https://github.com/apache/cordova-docs/blob/master/www/index.html
Creates a new blank Cordova project in the specified directory. Use `cordova help create` for more options.
```bash
$ cordova create MyApp
```
--------------------------------
### Leading Slash Example for Media Files
Source: https://github.com/apache/cordova-docs/blob/master/www/_posts/2023-09-12-camera-media-file-transfer-plugin-release.md
This example shows how to load media files by providing a URL with a leading slash, which navigates from the root directory ('www') of the app content.
```javascript
/file.mp4
```
--------------------------------
### Install Cordova InAppBrowser Plugin
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/plugin_ref/plugman.md
Use this command to install the InAppBrowser plugin for a specified platform and project directory.
```bash
plugman install --platform --project --plugin cordova-plugin-inappbrowser
```
--------------------------------
### Install Cordova Globalization Plugin
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/plugin_ref/plugman.md
Use this command to install the globalization plugin for a specified platform and project directory.
```bash
plugman install --platform --project --plugin cordova-plugin-globalization
```
--------------------------------
### Create Plugin Directory and Initialize npm Package
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/guide/hybrid/plugins/index.md
Use these commands to create a new directory for your plugin and initialize it as an npm package. The `-y` flag accepts all default values during initialization.
```zsh
mkdir cordova-plugin-echo
cd cordova-plugin-echo
```
```zsh
npm init -y
```
--------------------------------
### Create a Cordova Project
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/guide/cli/index.md
Use this command to create a new Cordova project directory with the required structure for your app. It initializes a basic web-based application.
```bash
cordova create hello com.example.hello HelloWorld
```
--------------------------------
### Install Cordova Geolocation Plugin
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/plugin_ref/plugman.md
Use this command to install the geolocation plugin for a specified platform and project directory.
```bash
plugman install --platform --project --plugin cordova-plugin-geolocation
```
--------------------------------
### Install Cordova Dialogs Plugin
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/plugin_ref/plugman.md
Use this command to install the dialogs plugin for a specified platform and project directory.
```bash
plugman install --platform --project --plugin cordova-plugin-dialogs
```
--------------------------------
### Create and Emulate an iOS App with Cordova CLI
Source: https://github.com/apache/cordova-docs/blob/master/www/_posts/2013-07-23-cordova-3.md
Use the Cordova command-line tool to create a new project, add the iOS platform, and then emulate it.
```bash
cordova create MyFunkyApp
cd MyFunkyApp
cordova platform add ios
cordova emulate ios
```
--------------------------------
### Install Cordova Contacts Plugin
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/plugin_ref/plugman.md
Use this command to install the contacts plugin for a specified platform and project directory.
```bash
plugman install --platform --project --plugin cordova-plugin-contacts
```
--------------------------------
### Create a New Cordova Electron Project
Source: https://github.com/apache/cordova-docs/blob/master/www/docs/en/latest/guide/platforms/electron/index.md
Steps to create a new Cordova project and add the Electron platform to it.
```bash
npm i -g cordova
cordova create sampleApp
cd sampleApp
cordova platform add electron
```
--------------------------------
### Launch Cordova Simulate from Command Line
Source: https://github.com/apache/cordova-docs/blob/master/www/_posts/2018-02-02-cordova-simulate.md
Launch Cordova Simulate for a specific platform by executing the 'simulate' command followed by the platform name.
```bash
simulate [platform]
```
```bash
simulate android
```
--------------------------------
### Build Android with Gradle Flag
Source: https://github.com/apache/cordova-docs/blob/master/www/_posts/2015-02-06-cordova-android-3.7.1.md
This command demonstrates how to build your Android project using Gradle, as mentioned in the release notes.
```bash
cordova build android -- --gradle
```
--------------------------------
### Install cordova-plugin-wkwebview-engine
Source: https://github.com/apache/cordova-docs/blob/master/www/_posts/2015-12-14-plugins-release.md
Use this command to install the cordova-plugin-wkwebview-engine. This plugin fixes a bug related to loading pages in cordova-plugin-inappbrowser.
```bash
cordova plugin add cordova-plugin-wkwebview-engine --save
```