Installing PhoneGap/Cordova on Windows and Linux

Installing PhoneGap/Cordova on Windows and Linux

This guide assumes you’re using either Windows 7/8 or a Debian-based Linux distribution. Using Linux is actually much easier, but if you don’t use it as your primary operating system, you’ll need to run it in a virtual machine. Emulating Android on top of a virtualized OS can be quite slow.

Table of Contents

  • Steps
    • Install the JDK (Java Developer Kit)
    • Download Eclipse/Android SDK or Android Developer Tools (ADT)
    • Install Android Build Tools, Rev. 19
    • Install Apache Ant
    • Install Node Package Manager (Node js NPM)
    • Install PhoneGap and Cordova
    • Set Up Android Virtual Device (AVD)
    • Use Cordova
  • Errors Encountered
    • “JAVA_HOME” Not Set
    • 32-bit Library Missing on Linux
    • Link NodeJS and Node Folders on Linux

 

Install the JDK

The JDK is the Java Development Kit (which allows you to compile Java). It can be downloaded from the Oracle site.

See Errors Encountered – “JAVA_HOME” NOT SET section for proper JDK installation on Windows if there is already a JRE present. It does not appear to be necessary on Linux.

 

Download Eclipse/Android SDK

First, download the appropriate Eclipse/Android SDK package from the Android site. Extract the downloaded files to a location where you can leave them permanently.

We now need to add this location to the PATH. Note that the locations in the commands must match the locations of the actual files/directories on your file system – the commands below are just examples.

On Linux:

$ export PATH=$PATH:/opt/java/adtlinux/sdk/platformtools:/opt/java/adtlinux/sdk/tools
$ echo $PATH

On Windows:

> setx PATH “%PATH%;C:\adt-windows\sdk\tools;C:\adt- windows\sdk\platform-tools”
::Exit command prompt and reopen for setx to take effect
> path

 

The final “echo $PATH” or “path” commands should display the current PATH variable, including the two additions we just made. You should also now be able to run the “android” command to start the Android SDK Manager. Note that it may take a few seconds for it to start up.

See Errors Encountered – 32-bit Libraries Missing on Linux if you’re using Linux and the ia32-libs library is missing.

 

Install Android Build Tools, Rev. 19

Because we’re using Cordova/PhoneGap 3.4, we need to use the compatible version of the Android Build tools, which is Revision 19.

1-Needs-Android-19

Once the Android Package Manager is open and loaded, you should see an “Install # Packages” button on the bottom-right. It should be instructing you to download the most recent versions of the Android SDK tools. I allowed it to install those, but in addition, I also installed “Tools – Android SDK Build-tools (Rev. 19)” as well as “Android 4.4.2 (API 19)” (and all of the tools within it). Some of the tools within the API most likely aren’t needed (like the Glass Development Kit Preview), but I downloaded them anyway. Note that you may need to check off “Show: Obsolete” if you don’t see version 19.

It may take a significant amount of time to download all of the necessary tools.

2-Install-Revision-19

Install Apache Ant

Apache Ant is a tool for automating the Java build process, and is required for Cordova to be able to build the .apk file that an Android phone can then install.

On Linux, run:

Ant should automatically be added to the PATH.

On Windows, download the appropriate setup file from the Apache site and extract it to a location you’ll remember. Since Ant is not automatically added to the PATH, run the following:

Note that you have to change the location/version in the command to the correct location/version of ant on your computer. To make sure it “stuck”, run the “ant” command in the command prompt. You should receive an ant-related error (specifically “Buildfile: build.xml does not exist!”), which means that the ant command has been run but it can’t actually build anything. If, however, you receive a message saying “‘ant’ is not recognized as an internal or external command”, it means you have not correctly added it to the PATH.

Install Node Package Manager

PhoneGap/Cordova is released as a package for NPM, the Node Package Manager. We’ll need to download it in order to issue the relevant commands for install PhoneGap/Cordova.

On Linux, run:

 

Build your first phonegap application

 

Share This

Share this post with your friends!