Please note that this guide was last updated on 30th May 2017. I haven’t worked with Cordova since 2018 and so the steps below are likely out of date and may not work. I’m keeping the guide here as a historical reference. If you are interested in providing updated instructions, please reach out to me and I will look to update this post accordingly.
To follow through this guide you’ll need:
Unfortunately you need a Mac to build an app for an iOS device. This guide will therefore include instructions for Android only.
This guide assumes you are running 64-bit Windows. If you don’t know what version you are running, it will almost certainly be 64-bit.
If you think you might be running a 32-bit install, then you should use the 32-bit installation files below. Wherever you see
64 bit, substitute this for
If you are in any doubt, or want to double check, follow these instructions:
The System type field will show the version of Windows you are running.
Briefly, these are steps you need to take:
The Git for Windows terminal is a superior alternative to the built-in Windows console application. We’ll be using it to run terminal commands.
The appropriate file should be downloaded. Once it has, double click to open and follow through with the installer, using all of the default options.
The Android SDK is used to build Android apps. There are a few steps involved to get the Android SDK:
We’ll cover these steps now.
.exefile has downloaded, open it.
To check that Java was installed correctly, open a terminal window and type
java -version. You should see the Java version printed to the terminal.
C:\drive folder. You should see a few folders here, including
When you are done, you should have a new folder at
We’ll now use the Command Line tools to install the SDK and other necessary tools.
cd C:/android/tools/bin ./sdkmanager.bat "build-tools;25.0.3" "emulator" "extras;intel;Hardware_Accelerated_Execution_Manager" "platforms;android-25" "platform-tools" "system-images;android-25;google_apis;x86" --verbose ./avdmanager.bat -v create avd -n x86 -k "system-images;android-25;google_apis;x86" -g "google_apis"
Make sure to accept the license agreement. Once these commands have completed, your
android folder should contain a whole bunch of new directories, including:
build-tools- these are the tools used by Cordova to build your Android app.
emulator- this is the Android emulator that will be used later to preview the app on your computer.
platforms- this is the Android SDK, separated by platform version. These correspond to the releases of Android: Nougat, Marshmallow, etc. The command above has downloaded the most recent platform version (25).
platform-tools- more tools that are used to administer Android devices on the command line.
system-images- these are images used by the emulator.
Gradle is a tool that is required by the Android SDK to build Android apps. It used to be included with the Android SDK, but now it must be downloaded and configured manually.
binary-onlyversion of the latest release and select it to begin the download.
gradlefolder to the
androidfolder that was created above.
In order to make this dizzying array of tools available to Cordova, and to us when using Git Bash, we need to set some environment variables. To do this:
We need to set three environment variables in total.
jdk. Select OK.
Pathitem under the System variables section and click the Edit… button. You should see a pane named Edit environment variable.
%ANDROID_HOME%\emulator %ANDROID_HOME%\gradle\bin %ANDROID_HOME%\platform-tools %ANDROID_HOME%\tools\bin
To test that all of this has worked, try typing the following into the terminal window:
adb version gradle -v
After running each command, you should see the respective tool print its version number. If any of these commands results in a
command not found, the environment has not yet been setup correctly. Please double check that the above steps have been carried out before continuing.
If you have got this far, congratulations! We have now set up the Android SDK. The next step is to install the Cordova CLI and create a sample app.
The Cordova CLI requires node.js. If you have already installed node, you can skip to the next section.
node -v. Node should print out its version number.
npm install -g cordova. This command may take a few minutes to complete. There may be nothing printed to the window for a short while - be patient, it is working!
When this finished, you should be able to run the command
cordova -v which should print the cordova version to the terminal.
We’ll now create a sample app which we can deploy to the emulator and device.
Open Git Bash and change to a folder where you are happy for code to live. The commands below will generate a new cordova project in a subdirectory of whichever folder you are currently in.
For example, if you have code living in folders at
C:\Users\<username>\Code, change to this directory before running the commands below.
Once you are in the correct directory, run the following:
cordova create cordova-hello-world cd cordova-hello-world cordova platform add android cordova build
These commands will create a new cordova project, add the Android platform, and build the respective files for deployment to Android. It might take a while!
Note: you may need to click through to allow various programs access to restricted parts of the system, such as the firewall.
Before continuing, please ensure that the commands above all worked correctly, with no errors. If there were any errors, you’ll need to go back and check that the Android SDK was installed correctly, and that you’ve set the environment variables correctly.
Before deploying to the emulator, there’s more stuff to install.
intelhaxm-android.exeand run through the installer.
Now we can deploy the app to the Android emulator. In the Git Bash window, type:
cordova emulate android
If all is well, the emulator should launch and display the app:
Note: If you see an error in the terminal such as
Intel virtualization technology (vt,vt-x) is not enabled when the emulator is starting, this means that your computer may not support the Android emulator. If you know how to access your computer’s BIOS, you can try to enable Hardware Virtualization. Otherwise, don’t worry about it - we’ll deploy to a real device instead.
If you have an Android phone or tablet running Android 4.4+, you can deploy the app to your device. You’ll need a USB cable to connect your device to your computer.
To begin, you need to configure your device to accept deployments from your computer:
Your device can now accept app deployments from your computer.
adb devices. You should see your device listed as attached in the terminal.
You can now deploy the app to your device:
cordova run android
After a short while, the app will be deployed and automatically opened on your device.
You’ve now got Cordova installed, configured and running on your computer, and you are able to deploy apps to the simulators and devices. You’re in good shape!
I’d recommend taking a look at the Ionic Framework, which builds on Cordova by providing a set of platform-specific UI components and additional build tools to help you build an awesome hybrid mobile app.