Working with Cordova Android project in Eclipse ADT

by

In the old versions of PhoneGap there was template project for android and same for other platforms. One would duplicate the template directory and import into eclipse, build paths to jar file in libs folder. After this you would easily build and test on a device.

Notice

Android studio intelij may be more suitable workflow if you are using Cordova for Android development.

The latest version Cordova 3.3 has a command line tool. Command Line Tool is used to download plugins from github or Cordova web service. One can understand the need to have Cordova work this way and CLI makes the copy paste nightmare it was, a lot easy. Just a few minor Gotchas when using standard tools(SDK - Software Development Kit) for Android with Cordova framework.  At first you think "I am not doing this right" the classic "operator error". When you look at the errors CLI (command line interface) tool is showing and what you see in eclipse along with logcat. Things start to click.

Before beginning this journey it's good to setup a solid development environment in either Windows or Mac.

Here are things needed for Windows 7

  1. ADT and SDK bundle Android Developer Website
  2. Java JDK
  3. Node js
  4. Git cmd tool
  5. Apache Ant
  6. Add "JAVA_HOME" variable to windows Environment variable with system path("C:\..") to jdk folder as Value
  7. Add system path for nodejs, sdk tools and platform tools, Apache Ant, Git to Windows "Path" Environment Variable
  8. Run npm command to install Cordova

Why it's best to use standard tool set?

  1. Fixing major functionality issues while developing.
  2. Later on you might start developing your own native plugins
  3. Your code will get complex and it's easier to nail down how Cordova Api is behaving with your Js code
  4. More good reasons (http://cordova.apache.org/docs/en/3.3.0/guide_overview_index.md)

Proper way to import cordova project to Eclipse

Most common issues are errors when Android folder inside platforms folder of your Cordova project is imported incorrectly. You will also see errors when class folder isn't added to build path.

After building your Android project using Cordova command Line Tool, import android folder from your Cordova project into eclipse and debug any issues by looking at logcat. if you don't have logcat panel you can easily add it in eclipse.

Click Window -> show view -> other from top menu.

  1. Select from top menu on Eclipse IDE File -> import
  2. Be sure to select "Existing Android Code into workspace"
  3. on the next screen don't check mark "copy the project folder".
  4. For "Root Directory" field click browse to select android folder in your Cordova project under platforms.
  5. There will be two things checked (Android project and CordovaLib). leave them checked
  6. Click finish

Add CordovaLib class folder

Adding CordovaLib class folder to build paths in eclipse is suppose to replace adding .jar file to your project. Doesn't work consistently when cleaning and building your Cordova Android project using ADT eclipse on a Mac.

Card Title

Window after clicking build paths in eclipse ADT.

  1. Right click on project
  2. Mouse over "build path" and click "Configure Build Path" (you should see a window pictured above.)
  3. Press "add class folder"
  4. cordova-eclipse-add-class-folder lazyload
  5. Click on "Android Dependency.." in the list and delete it
  6. Clean and build project
 

How to create a jar file (Back to the Future)

If you are on a Mac you might need to create a Cordova jar file due to lot of errors.

  1. Download source zip from http://cordova.io
  2. Unzip and inside cordova-android folder in README.md file gives these instructions
  3. cordova-eclipse-build-without-cli lazyload
  4. In terminal cd into framework folder
  5. 
     
    
                    cd framework
                    android update project -p . -t android-19
    Note: The period after p tells your computer to run android update project command with -p option in current directory and android-19 is the latest Api for android..be sure you cd into "cordova-3.3.0/cordova-android/framework" folder first. Android command won't work if you don't have system path added for tools, and platform-tools folder inside your Android sdk folder.

Hey, there is the old goodie .jar file with a new name. Add it to libs folder in your android Cordova project.

  1. Copy cordova-3.3.0.jar file into libs folder of your project (cordova-project-folder/platform/
  2. Right click project folder and click refresh (to refresh the libs folder if it's empty in eclipse)
  3. As Explained above when class folder was added to project. Right click project folder in eclipse and go to configure build paths window in eclipse.
  4. Press "Add JARS" and you get a popup window to select jar file.
  5. adding-cordova-jar-file-to-eclipse-project lazyload

Error initializing Cordova class not found

LogCat

LogCat screen shot.

This error means your Cordova application is missing plugins. Since even device plugin isn't their to issue device ready. Add plugins to your Cordova project using command line tool, clean and build your project in ADT eclipse and error will go away. If command line tool reports errors while trying to build for Android platform check if Apache Ant is installed and system environment variable Path is updated. Remember after you update Path you need to close and open cmd or terminal window again.

Depending on how complex you want to make your App. You don't have to even touch SDK and CLI tools to get started with your App. You can use a google chrome browser,a basic text editor, HTML markup, CSS markup, Javascript programming, understanding of basic programming principles and logic.

There is a build service by Adobe (http://build.phonegap.com) you can use to package your Apps.

Z Data Tech https://www.zdatatech.com/logo/zdatatech-logo.png Last modified: January 30, 2023
Suggested
Advertisement