Android Platform Guide

This guide shows how to set up your SDK development environment to deploy Cordova apps for Android devices. It walks you through the process of installing the Android SDK, opening an Android project in Eclipse SDK, and deploying to an emulator or device. You will need to follow this guide to at least Install the Android SDK, regardless of which workflow you are following. (Both the Web Project Dev and Native Platform Dev workflows require the Android SDK to be installed and accessible via your PATH.)

See the following for more detailed platform-specific information:

The command-line tools above refer to versions prior to Cordova 3.0. See The Command-Line Interface for information about the current interface.

Requirements and Support

Cordova for Android requires the Android SDK. See the Android SDK's System Requirements.

Cordova supports Android 2.3.x (Gingerbread, starting with Android API level 10) and 4.x. As a general rule, Android versions become unsupported by Cordova as they dip below 5% on Google's distribution dashboard. Android versions earlier than API level 10, and the 3.x versions (Honeycomb, API levels 11-13) fall significantly below that 5% threshold.

Developers should use the cordova utility in conjunction with the Android SDK. See The Command-Line Interface for information how to install it, add projects, then build and deploy a project.

Install the Android SDK from developer.android.com/sdk. The android sdk is distributed as an 'adt-bundle---' file. On windows, the adt-bundle is packaged with an installer. On OSX and Linux, simply unpack the 'adt-bundle' in the location you store development tools. More detailed information on Android SDK setup can be found here

For Cordova command-line tools to work, you need to include the SDK's tools and platform-tools directories in your PATH environment. On Mac, you can use a text editor to create or modify the ~/.bash_profile file, adding a line such as the following, depending on where the SDK installs:

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

This exposes SDK tools in newly opened terminal windows. Otherwise run this to make them available in the current session:

$ source ~/.bash_profile

To modify the PATH environment on Windows 7:

  • Click on the Start menu in the lower-left corner of the desktop, right-click on Computer, then click Properties.

  • Click Advanced System Settings in the column on the left.

  • In the resulting dialog box, press Environment Variables.

  • Select the PATH variable and press Edit.

  • Append the following to the PATH based on where you installed the SDK, for example:

    ;C:\Development\adt-bundle\sdk\platform-tools;C:\Development\adt-bundle\sdk\tools
    
  • Save the value and close both dialog boxes.

You may also need to enable Java and Ant. Open a command prompt and type java, and also type ant. Append to the PATH whichever fail to run:

    ;%JAVA_HOME%\bin;%ANT_HOME%\bin

Open a Project in the SDK

Use the cordova utility to set up a new project, as described in The Cordova The Command-Line Interface. For example, in a source-code directory:

    $ cordova create hello com.example.hello "HelloWorld"
    $ cd hello
    $ cordova platform add android
    $ cordova build

Once created, you can use the Eclipse that comes along with the Android SDK to modify it:

  • Launch the Eclipse application.

  • Select the New Project menu item.

  • Choose Android Project from Existing Code from the resulting dialog box, and press Next:

  • Navigate to hello, or whichever directory you created for the project, then to the platforms/android subdirectory.

  • Make sure both hello and hello-CordovaLib projects are selected to be imported. The hello-CordovaLib project is needed as of Cordova 3.3.0 because Cordova is now used as an Android Library instead of a .jar file.

  • Press Finish.

Once the Eclipse window opens, a red X may appear to indicate unresolved problems. If so, follow these additional steps:

  • Right-click on the project directory.

  • In the resulting Properties dialog, select Android from the navigation pane.

  • For the project build target, select the highest Android API level you have installed.

  • Click OK.

  • Select Clean from the Project menu. This should correct all the errors in the project.

Deploy to Emulator

You can use the cordova utility to run an app in an emulator, or you can run it within the SDK. Either way, the SDK must first be configured to display at least one device. To do so, use the Android SDK Manager, a Java application that runs separately from Eclipse. There are two ways to open it:

  • Run android on the command line.

  • From within Eclipse, press this toolbar icon:

Once open, the Android SDK Manager displays various runtime libraries:

Choose Tools → Manage AVDs (Android Virtual Devices), then choose any item from Device Definitions in the resulting dialog box:

Press Create AVD, optionally modifying the name, then press OK to accept the changes:

The AVD then appears in the Android Virtual Devices list:

To open the emulator as a separate application, select the AVD and press Start. It launches much as it would on the device, with additional controls available for hardware buttons:

At this point you can use the cordova utility to deploy the application to the emulator from the command line:

    $ cordova emulate android

If instead you work within Eclipse, right-click the project and choose Run As → Android Application. You may be asked to specify an AVD if none are already open.

For a faster experience, you can use the Virtual Machine Acceleration to improve the execution speed. Many modern CPUs provide extensions to execute Virtual Machines more efficiently. Before attempting to use this type of acceleration, you need to determine if your current development system's CPU, supports one the following virtualization technologies:

  • Intel Virtualization Technology (VT-x, vmx) → Intel VT-x supported processor list
  • AMD Virtualization (AMD-V, SVM), only supported for Linux (Since May 2006, all CPUs AMD include AMD-V, except Sempron).

Another way to find out if your Intel processor supports VT-x Technology, it's by executing the Intel Processor Identification Utility, for Windowsyou can download it from the Intel Download Center, or you can use the booteable utility, which is OS Independent.

After install and execute the Intel Processor Identification Utility over Windows, you will get the following window, in order to check if your CPU supports the Virtualization Technologies:

In order to speed up the emulator, you need to download and install one or more Intel x86 Atom System Images, as well as the Intel Hardware Accelerated Execution Manager (HAXM).

Open your Android SDK Manager, and select the Intel x86 Atom System Image, for whichever version that you want to test. Then go to Extras and select Intel x86 Emulator Accelerator (HAXM), and install those packages:

After download, run the Intel installer, which is available within your Android SDK at extras/intel/Hardware_Accelerated_Execution_Manager. Note:If you have any problems installing the package, you can find more information and step by step guidance check this Intel Article.

Once installed, in order to test it, create new a AVD with the CPU/ABI set to an Intel (Atom) x86 Image:

If you are using Linux-based system, follow the instructions in the Android Developer Site.

When starting the emulator, ensure there are no error messages indicating a failure to load HAXM modules.

Deploy to Device

To push an app directly to the device, make sure USB debugging is enabled on your device as described on the Android Developer Site, and use a mini USB cable to plug it into your system.

You can push the app to the device from the command line:

    $ cordova run android

Alternately within Eclipse, right-click the project and choose Run As → Android Application.