Cordova – First Application

We have understood how to install Cordova and set up the environment for it. Once everything is ready, we can create our first hybrid Cordova application.

Step 1 – Creating App

Open the directory where you want the app to be installed in the command prompt. We will create it on the desktop.

C:\Users\username\Desktop>cordova 
   create CordovaProject io.cordova.hellocordova CordovaApp
  • CordovaProject is the directory name where the app is created.
  • io.cordova.hellocordova is the default reverse domain value. You should use your own domain value if possible.
  • CordovaApp is the title of your app.

Step 2 – Adding Platforms

You need to open your project directory in the command prompt. In our example, it is theĀ Cordova project. You should only choose platforms that you need. To be able to use the specified platform, you need to have installed the specific platform SDK. Since we are developing on windows, we can use the following platforms. We have already installed Android SDK, so we will only install the android platform for this tutorial.

C:\Users\username\Desktop\CordovaProject>cordova platform add android 

There are other platforms that can be used on Windows OS.

C:\Users\username\Desktop\CordovaProject>cordova platform add wp8 
C:\Users\username\Desktop\CordovaProject>cordova platform add amazon-fireos 
C:\Users\username\Desktop\CordovaProject>cordova platform add windows 
C:\Users\username\Desktop\CordovaProject>cordova platform add blackberry10
C:\Users\username\Desktop\CordovaProject>cordova platform add firefoxos 

If you are developing on Mac, you can use āˆ’

$ cordova platform add IOS 
$ cordova platform add amazon-fireos 
$ cordova platform add android 
$ cordova platform add blackberry10 
$ cordova platform add firefoxos 

You can also remove the platform from your project by using āˆ’

C:\Users\username\Desktop\CordovaProject>cordova platform rm android 

Step 3 – Building and Running

In this step, we will build the app for a specified platform so we can run it on a mobile device or emulator.

C:\Users\username\Desktop\CordovaProject>cordova build android 

Now we can run our app. If you are using the default emulator you should use āˆ’

C:\Users\username\Desktop\CordovaProject>cordova emulate android 

If you want to use the external emulator or real device you should use āˆ’

C:\Users\username\Desktop\CordovaProject>cordova run android 

NOTEĀ āˆ’ We will use theĀ Genymotion android emulatorĀ since it is faster and more responsive than the default one. You can find the emulatorĀ here. You can also use a real device for testing by enablingĀ USB debuggingĀ from the options and connecting it to your computer via USB cable. For some devices, you will also need to install the USB driver.

Once we run the app, it will install it on the platform we specified. If everything is finished without errors, the output should show the default start screen of the app.

In our next tutorial, we will show you how to configure the Cordova Application.

Leave a Reply