license: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
This guide shows how to set up your SDK development environment to deploy Cordova apps for Android devices. See the following for more detailed platform-specific information:
The command-line tools above refer to versions prior to Cordova 3.0. See The Cordova Command-line Interface for information about the current interface.
See the System Requirements for the Android SDK.
Cordova supports Android 2.2, 2.3, and 4.x. As a general rule, platforms are deprecated as they dip below 5% on Google's distribution dashboard.
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. You may be presented with a choice of where to install the SDK, otherwise move the downloaded adt-bundle
tree to wherever you store development tools.
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
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 "Hello World" $ cd hello $ cordova platform add android $ cordova build
Once created, here's how to use the SDK to modify it:
hello
, or whichever directory you created for the project, then to the platforms/android
subdirectory.Once the Eclipse window opens, a red X may appear to indicate unresolved problems. If so, follow these additional steps:
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 are working 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, use an Intel-based emulator image:
Intel x86 Atom
System Images as well as the Intel Hardware Accelerated Execution Manager
, available under Extras.extras/intel/Hardware_Accelerated_Execution_Manager
.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.