Apache Cordova

Installing the Cordova CLI: The Cordova command-line tool is distributed as an npm package. https://www.npmjs.com/package/cordova

To install the cordova command-line tool, follow these steps:

1. Download and install Node.js. On installation you should be able to invoke node and npm on your command line. 2. (Optional) Download and install a git client, if you don't already have one. Following installation, you should be able to invoke git on your command line. The CLI uses it to download assets when they are referenced using a url to a git repo.

3. Install the cordova module using npm utility of Node.js. The cordova module will automatically be downloaded by thenpm utility.  on OS X and :

$ sudo npm install -g cordova

 on Windows:

C:\>npm install -g cordova

Create Hello World Example:

Go to the directory where you maintain your source code, and create a cordova project:

$ cordova create hello com.example.hello HelloWorld

This creates the required directory structure for your cordova app. By default, the cordova create script generates a skeletal web-based application whose home page is the project's www/index. file.

Add Platforms: All subsequent commands need to be run within the project's directory, or any subdirectories:

$ cd hello

Add the platforms that you want to target your app. We will add the '' and 'android' platform and ensure they get saved toconfig.xml:

$ cordova platform add ios --save $ cordova platform add android --save

To check your current set of platforms:

$ cordova platform ls

Install pre-requisites for building: To build and run apps, you need to install SDKs for each platform you wish to target. Alternatively, if you are using browser for development you can use browser platform which does not require any platform SDKs.

$ cordova platform add browser $ cordova run browser

To check if you satisfy requirements for building the platform:

$ cordova requirements Requirements check results for android: Java JDK: installed . Android SDK: installed Android target: installed android-19,android-21,android-22,android-23, Inc.:Goo gle :19,Google Inc.:Google APIs (x86 System Image):19,Google Inc.:Google APIs:23 Gradle: installed Requirements check results for ios: Apple OS X: not installed Cordova tooling for iOS requires Apple OS X Error: Some of requirements check failed Android Platform

This guide shows how to set up your SDK environment to deploy Cordova apps for Android devices, and how to optionally use Android-centered command-line tools in your development workflow. You need to install the Android SDK regardless of whether you want to use these platform-centered shell tools or cross-platform Cordova CLI for development. For more information visit: http://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html#requirements-and- support Requirements and Support Cordova for Android requires the Android SDK which can be installed on OS X, Linux or Windows. See the Android SDK'sSystem Requirements. Cordova's latest Android package supports up to Android API-Level 23. Installing the Requirements

Java Development Kit (JDK)

Install Java Development Kit (JDK) 7 or later.

When installing on Windows you also need to set JAVA_HOME Environment Variable according to your JDK installation path (see Setting Environment Variables) Android SDK Install the Android Stand-alone SDK Tools or Android Studio. Proceed with Android Studio if you plan on developing new Cordova for Android plugins or using native tools to run and debug the Android platform. Otherwise, the Android Stand-alone SDK Tools are enough to build and deploy Android applications. Detailed installation instructions are available as part of installation links above. Adding SDK Packages After installing the Android SDK, you must also install the packages for whatever API level you wish to target. It is recommended that you install the highest SDK version that your version of cordova- android supports (see above).

Open Android SDK Manager (for example, run android from the terminal) and make sure the following are installed:

1. Android Platform SDK for your targeted version of Android 2. Android SDK build-tools version 19.1.0 or higher 3. Android Support Repository (found under "Extras")

See Android's documentation on Installing SDK Packages for more details. Setting environment variables

In certain cases you may need to set them manually. The following variables should be updated:

1. Set the JAVA_HOME environment variable to the location of your JDK installation 2. Set the ANDROID_HOME environment variable to the location of your Android SDK installation 3. It is also recommended that you add the Android SDK's tools and platform- tools directories to your PATH

OS X and Linux

On a Mac or Linux, you can use a text editor to create or modify the ~/.bash_profile file. To set an environment variable, add a line that uses export like so (substitute the path with your local installation):

export ANDROID_HOME=/Development/android-sdk/

To update your PATH, add a line resembling the following (substitute the paths with your local Android SDK installation's location):

export PATH=${PATH}:/Development/android-sdk/platform-tools:/Development/android- sdk/tools

Reload your terminal to see this change reflected or run the following command:

$ source ~/.bash_profile

Windows These steps may vary depending on your installed version of Windows. Close and reopen any command prompt windows after making changes to see them reflected 1. Click on the Start menu in the lower-left corner of the desktop 2. In the search bar, search for Environment Variables and select Edit the system Environment Variables from the options that appear 3. In the window that appears, click the Environment Variables button To create a new environment variable:

1. Click New... and enter the variable name and value

To set your PATH: 1. Select the PATH variable and press Edit. 2. Add entries for the relevant locations to the PATH:

3. C:\Development\android-sdk\platform-tools 4. C:\Development\android-sdk\tools Project Configuration

Setting up an Emulator

If you wish to run your Cordova app on an Android emulator, you will first need to create an Android Virtual Device (AVD). See the Android documentation for managing AVDs and the instructions for configuring the emulator and setting up hardware acceleration. Once your AVD is configured correctly, you should be able to see it by running this command from within a Cordova project:

$ cordova run --list

Build the App

By default, cordova create script generates a skeletal web-based application whose start page is the project'swww/index.html file. Any initialization should be specified as part of the deviceready event handler defined inwww/js/index.js. Run the following command to build the project for all platforms:

$ cordova build

You can optionally limit the scope of each build to specific platforms - 'ios' in this case:

$ cordova build ios

See Also

 Cordova build command reference documentation Test the App SDKs for mobile platforms often come bundled with emulators that execute a device image, so that you can launch the app from the home screen and see how it interacts with many platform features. Run a command such as the following to rebuild the app and view it within a specific platform's emulator:

$ cordova emulate android $ cordova run android