How to setup and build cordova application for Android

Date : 22/08/2019


Apache Cordova is an open-source mobile development framework. It allows you to use standard web technologies – HTML5, CSS3, and JavaScript for cross-platform development. So we can use it in any kind of platforms. It will come under hybrid apps categories.

In cordova, there are certain plugins are used to to communicate with os and HTML/CSS. In the following tutorial we will see how to create cordova application.

Installing the Cordova CLI

The Cordova command-line tool is distributed as an npm package. Firstly, install npm package.

In Windows:

C:\>npm install -g cordova

In IOS and LInux:

$ sudo npm install -g cordova

g is we are set this up as globally.

Create Your App

Navigate to the directory you want to install the application. Make sure you are root user or running these commands using sudo. And run this command

cordova create demoapp Hey!

Just this. Now you have create cordova app. Do this

cd demoapp

Run this command to add whatever platform you want to add. You can check available platform. You can also check the requirement for a platform. For this run

cordova paltform android requirements

Before, you should have added the platform in your project. Do this

cordova platform add android

You can add any number of platform in your project. To know more about what you can do, run cordova --help, cordova platform --help

Environment setup

We will setup environment for android platform. In android studio, you need

  • gradle
  • jdk 8
  • Sdk

Narmally, you would have Sdk in your android studio. If not, download it in sdk manager.

We have to setup environmental variables. It would be like for example,

for java , JAVA_HOME=/home/karna/jdk-8u131-linux-x64/jdk1.8.0_131

for sdk, ANDROID_HOME=/home/******/Android/Sdk, PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$ANDROID_HOME/build-tools

The above is enough to run the project.

Run on Device or Emulator

Make sure you are running these as root if you setup environment variables as root. You can install the app on android device via usb by running this.

cordova run android --device

Or on emulator

cordova run android

You can see the default cordova app running with their platform’s image on the device.

For more,

If you like it, share it with friends to keep writing more article. Reasonable criticism are most welcome.

For more articles, visit our website.

Leave a Reply