Cordova Installation in Windows 8 Part 2
August 31, 2014 4:01 pm Leave your thoughtsContributed by Arthur K
Continuing from part 1, we will now setup Apache Ant, Android SDK and prepare our first application.
Apache Ant
The easiest way to install Ant is using “npm install –g ant”, but somehow on my machine it only installed version 1.8.4 and would not work with current JDK version that we installed before. I found that there is a zipped latest version (currently 1.9.4), in their website that you can download.
Download Apache Ant here: http://ant.apache.org/bindownload.cgi
If you already installed Ant using npm, you can overwrite the file created using files from the zip file you just downloaded. Usually it is installed under:
1 |
C:\Users\<Username>\AppData\Roaming\npm\node_modules\ant |
If this is your fresh install, you can put it under any preferred directory. However you will need to take a note on the installation directory as we will need to add it on the PATH environment as we did with Java in part 1.
1 2 |
// check ant version ant -v |
If above code is not working when you entered it on command prompt, means you need to add Ant to your environment PATH.
On the System variables:
1 2 |
Name : ANT_HOME Value : C:\Users\<Username>\AppData\Roaming\npm\node_modules\ant\ant |
It is important to replace <Username> with your username. Try to browse the directory to confirm you get the right one up until you can see “bin” directory.
On User variables for <Username>:
1 |
PATH value : ;%ANT_HOME%\bin |
Again, it is important not to delete or modify your previous PATH value, only append and use “;” as a separator from your existing PATH values.
You would need to double check if you can run “ant –v” on command prompt and getting return of “Apache Ant(TM) version 1.9.4 compiled on April 29 2014”, otherwise you would end up receiving Cordova error when trying to add platform on your application.
Android SDK
This is the final step before we are able to use Cordova to create our apps. The good news is that there is a new IDE based on the famous IntelliJ, called the Android Studio that you can download for free. The choice is yours of course whether to install an IDE package or just the SDK.
Download Android SDK here: https://developer.android.com/sdk/installing/studio.html
Follow the installation steps and when its done, add the directory path to your environment PATH using same way as previously done with Java and Ant.
On the System variables:
1 2 |
Name : ANDROID_SDK Value : C:\Program Files (x86)\Android\android-studio\sdk |
It is important to replace <Username> with your username. Try to browse the directory to confirm you get the right one up until you can see “tools” directory and “platform-tools”
On User variables for <Username>, we need to add two path to the “tools” directory and “platform-tools” directory:
1 |
PATH value : ;%ANDROID_SDK%\tools;%ANDROID_SDK%\platform-tools; |
Again, do not to delete or modify your previous PATH value, only append and use “;” as separator from your existing previous PATH value.
After adding two paths above, you can run “android” on the command prompt to bring up Android SDK Manager to download and install all files under “API 19” needed by Cordova version 3.5.0. This process will take a while depends on your internet connection speed as the files are quite large.
Preparing Your First Android Application
Finally we reached the most exciting part, preparting your Android application. Navigate to your preferred directory where you want to develop your application, then use the Cordova create command.
1 |
cordova create <directory> <id> <title> |
where:
<directory> is your future app directory, for example “supreme”
<id> is the optional identifier of your application, for example “com.example.supreme”
<title> is the optional title of your application, for example “Supreme”
Therefore, altogether it would be:
1 |
cordova create supreme com.example.supreme Supreme |
This Supreme apps is still blank and a target platform would need to be added inside. In this case we want to build an Android app. We will need to navigate to supreme folder.
1 |
dir supreme |
Then add the android platform inside our application directory.
1 |
cordova platform add android |
That’s it, preparing your first app is very simple. In the upcoming posts we will talk about building your first application.
Possible Problems
Here is a list of common problems and the ways to fix them.
Ant not found
Cordova error below when trying to add platform on your application.
1 2 3 4 5 6 7 8 9 10 |
E:\lab\expnote>cordova platforms add android Downloading cordova library for android... Download complete Creating android project... C:\Users\<Username>\.cordova\lib\android\cordova\3.5.0\bin\node_modules\q\q.js:12 6 throw e; ^ Error: ERROR : executing command 'ant', make sure you have ant installed and added to your path. |
This problem happens because PATH environment is not setup properly under local machine. The easiest way to check whether you get the correct path is by browsing using explorer up until you see “bin” directory of Ant.
For my local machine, it would be under:
1 |
C:\Users\<Username>\AppData\Roaming\npm\node_modules\ant\ant |
Set environment as follow,
System variables
1 2 |
Name : ANT_HOME Value : C:\Users\<Username>\AppData\Roaming\npm\node_modules\ant\ant |
Append PATH value on User variables for <Username>
1 |
;%ANT_HOME%\bin |
Error javac1.8
Cordova cannot build android error javac1.8
This problem happens when ant version <1.9.0 is used which is not compatible with current JDK 8. It is can be easily solved by updating Ant to latest version available from web.
Closing
That’s it for installation of cordova under Windows 8. Stay tuned for the next chapter in the Cordova contribution, which is creating your first application.
Tags: Android, cordova
Categorised in: Android, Cordova, Software Development