Android

Requirements and Support

Cordova for Android requires the Android SDK which can be installed on OS X, Linux or Windows. The supported Android API Levels and Android Versions for the past few cordova-android releases can be found in this table:

cordova-android Version Supported Android API-Levels Equivalent Android Version
6.X.X 16 - 25 4.1 - 7.1.1
5.X.X 14 - 23 4.0 - 6.0.1
4.1.X 14 - 22 4.0 - 5.1
4.0.X 10 - 22 2.3.3 - 5.1
3.7.X 10 - 21 2.3.3 - 5.0.2

Installing the Requirements

Java Development Kit (JDK)

  • Install Java Development Kit (JDK) 8 or later.
  • When installing on Windows you also need to setJAVA_HOMEEnvironment Variable according to your JDK installation path.

Android SDK

  • Install Android Studio. Detailed installation instructions are on Android's developer site.

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.

  • Open the Android SDK Manager (runandroidorsdkmanagerfrom 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

Cordova's CLI tools require some environment variables to be set in order to function correctly. The CLI will attempt to set these variables for you, but 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

Installing the Cordova CLI

  • The Cordova command-line tool is distributed as an npm package.
  • To install thecordovacommand-line tool, follow these steps:

    1. Download and install Node.js. On installation you should be able to invokenodeandnpmon 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 invokegiton your command line. The CLI uses it to download assets when they are referenced using a url to a git repo.

    3. Install thecordovamodule usingnpmutility of Node.js. Thecordovamodule will automatically be downloaded by thenpmutility:

    $ npm install -g cordova
    

Deploy the App

Create the App

  • 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, thecordova createscript generates a skeletal web-based application whose home page is the project'swww/index.htmlfile (see in Sample code).

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 'android' platform and ensure they get saved toconfig.xmlandpackage.json:
$ cordova platform add android
  • To check your current set of platforms:
$ cordova platform ls
  • To check if you satisfy requirements for building the platform:
$ cordova requirements
  • Run the following command to prepare the project for android platforms (if you change code in HTML file or Cordova APIs JS file):
$ cordova prepare android
  • Run the following command to build the project for android platforms:
$ cordova build android
  • Run the following command to run the project for android platforms on emulate or real device:
$ cordova run android

results matching ""

    No results matching ""