Creating an App

Android Software

You have to choose a particular mobile platform for your app and install any additional software required by it. If you want to develop Android apps then you need to add an Android platform, and install Java and an Android SDK (Software Development Kit).

Java

The first task is to install the Java JDK (Java Development Kit) if it is not already installed in your computer. The latest version of JDK SE is required, at present JDK 1.8, which can be downloaded from the oracle.com website.

Again it can be downloaded then run from the browser or by double clicking the downloaded application from your Downloads folder.

When the installation is completed you should go to the environmental variables window again and check that there is now a JAVA_HOME environment variable and it is set to the Java path in your file system. If not then, of course, you have to add the variable or edit its present value to its correct path in your computer.

Android SDK

To get an Android SDK you have to install the Android tools application. You can then install a specific SDK from that. You can download this from https://developer.android.com/studio/

You should download only the command line tools and not the entire Android Studio which is not required (unless you decide later to use it to write your apps). It is downloaded into a zip folder probably in your Downloads folder again. However, you will be using this folder in the development process so it is better to extract it to a more convenient location, such as the root folder, C and rename it. I use C:\AndroidTools. You can unzip the folder into this location and complete the operation by ensuring that the ANDROID_HOME environmental variable is set to the this folder. The Android tools should be inside the AndroidTools folder.

When the tools application has been installed you can check this by using the CLI to list all the tools contained in it with the command,

sdkmanager --list

This should print a list - a very long list enitled "platform-tools", from which you have to choose a selection to install. You need a recent API, such as Android 8 (SDK26), which is "platforms;android-26" and a corresponding build-tools, such as "build-tools;26.0.3". If you want to use an emulator you can include "system-images;android-26;google_apis;x86" and "extras;intel;Hardware_Accelerated_Execution_Manager". Then there are some tools we will require in the plugins section, such as "extras;android;m2repository" and "extras;google;m2repository". For now we will settle for the command

sdkmanager "platform-tools" "platforms;android-26" "build-tools;26.0.3" "extras;android;m2repository" "extras;google;m2repository"

At this point you should be able to start developing a Cordova Android app, although, as Android evolves, you may have to repeat this procedure to install newer SDKs.

 

Creating an App

Unlike the commands we have used so far, the Cordova CLI commands should be entered in a Cordova project directory. They are local commands. Like other software, a Cordova app is developed as a project and all the required files are contained in the project folder. We can keep all our projects in one folder. You can create the folder in Windows or the command prompt as described above. Then we can navigate into that folder and enter the Cordova command to create a new project.

If we put all our Cordova projects in a root folder called Web in the disc C we would end up with a folder C:\Web where we can put all our projects as subfolders.

Back in the Command Prompt we can create our first Cordova app by creating a new project. We will navigate to the Web folder and create the app from there. In addition we will need three names. One is the project name. This must be a new folder name and not an existing one. Cordova will create the folder. Then we need an ID or package name. This has to be a universally unique name so that it is the only instance in an app store or a device, otherwise it will not be installed. The standard formula for constructing a unique name is to use the reverse of a domain name registered to you, appended with the app name, all in lower case. Then it has a name that is displayed under the app icon on a device. This is the App Name. It need not be unique. In Android development it is often the same as the project name but by default Cordova gives it the name HelloCordova. So you might like to change this.

To start developing a new app called Starter, in the Web folder, with a package name of com.example.starter (yes, all in lower case), we can go to C:\Web and use

cordova create Starter com.example.starter Starter

Here the first Starter is the project and folder name, com.example.starter is the ID or package name. This is OK for local development but you must replace it with your own reverse domain name in any apps you intend to publish. And the final Starter is the app name that appears as the icon label on your Android device.

This command creates a new Starter directory in C:\Web which is the new project directory. You can select it with cd Starter and use dir to list its contents. It has all the files required to create a new project.

 

Adding a Platform

A new app must have a platform so when you start working on a new app you have to select and install a platform. Then you have to install a target and an Android SDK as described below. You can see what platforms are already installed in the project and those that are available to be installed with

C:\Web\Starter cordova platform

Since none have been installed yet, the first list should be empty. So we can add an Android platform with

C:\Web\Starter cordova platform

If none have been installed yet, the first list will be empty. So we can add an Android platform with

C:\Web\Starter cordova platform add android

This will also try to build an Android project. If the build is successful you can check the status of its Cordova project with

C:\Web\Starter cordova requirements

This should show that Cordova, Java, Android and Gradle are all available in the project directory. Otherwise you should check the previous procedures have been executed correctly. You can also check again for any existing platforms with

C:\Web\Starter cordova platform

This should show only the Android platform.