Knowledge is power. We love to share it.

News related to Mono products, services and latest developments in our community.


Building Cordova 2.2.0

12/20/2012Categories: Mobile

This post will explain how to build cordova-2.2.0.jar from source since, as it doesn't come bundled with the download from Cordova Apache incubator website. In addition, I'll explain how to run your first Cordova HelloWorld application. Missing cordova-2.2.0.jar file is causing the infamous "The import org.apache.cordova cannot be resolved" error. You should have Eclipse, Android SDK and the ADT plugin already installed on your machine, the PATH environment variables should be set up . Create a new project using:

./create <project_folder_path> <package_name> <project_name>

First we will build cordova-2.2.0.jar. Extract the archive from the After that, open Eclipse and go to: "File -> Import -> General -> Existing Projects into Workspace", click "next" and then in the "Select root directory" browse to "incubator-cordova-android/framework". You can also select "Copy projects into workspace" option if you want, but it is not necessary (it might be a good idea to do it if you want to keep all your projects in the same place). Click "Finish".

Next, you will have to download the commons codec from Apache Commons website, extract it and copy the commons-codec-1.7.jar to your Cordova/libs directory (if the libs directory is missing, create it). Right-click on your Cordova project and click "refresh" and after that, expand the Cordova/libs directory in your "Package Explorer", right-click on the commons-codec-1.7.jar and select "Build Path -> Configure Build Path". Check commons-codec-1.7.jar and click "Ok". Right-click on your Cordova project in the "Package Explorer" again and select "Android Tools -> Fix Project Properties"

In the "Package Explorer", right-click on your project one more time and go to "Properties". Select the "Android" tab on the left side and select the latest Android target name available. Click "Apply" and "Ok".

If you wish to use Android 4.2 or higher, expand "Cordova/src/org.apache.cordova/" and open for editing. You will have to comment out the following two lines:

if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB)

Since "Android 4.2", setNavDump() is deprecated and you won't be able to build Cordova with it (check this link for more details). If you're fine with using "Android 4.1.2", you can leave the as it is.

Now you can build the Cordova project ("Project" -> "Build project"). You will find the newly created cordova.jar file in Cordova/bin which you will need in the next step.
Next, import your HelloWorld project into Eclipse as described here . Then copy the cordova.jar from the previous step to your project to "HelloWorld/libs" directory and rename it to cordova-2.2.0.jar. Now go to previously extracted "incubator-cordova-android/framework/assets/js" and copy the to "HelloWorld/assets/www/" and then rename it to cordova-2.2.0.js. Right-click to HelloWorld and click "refresh" and lastly, select the same SDK as you did for the Cordova project (for example "Android 4.2").

Now you are ready to build your HelloWorld app. Connect your device and build the project. The app should run on your device with an image that looks like this:

Small image
Rated 3.67, 3 vote(s). 
By mev9669
Download link broken.
I fixed the links, apache archived the files.