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.
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
- ADT and SDK bundle Android Developer Website
- Java JDK
- Node js
- Git cmd tool
- Apache Ant
- Add "JAVA_HOME" variable to windows Environment variable with system path("C:\..") to jdk folder as Value
- Add system path for nodejs, sdk tools and platform tools, Apache Ant, Git to Windows "Path" Environment Variable
- Run npm command to install Cordova
Why it's best to use standard tool set?
- Fixing major functionality issues while developing.
- Later on you might start developing your own native plugins
- Your code will get complex and it's easier to nail down how Cordova Api is behaving with your Js code
- 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.
- Select from top menu on Eclipse IDE File -> import
- Be sure to select "Existing Android Code into workspace"
- on the next screen don't check mark "copy the project folder".
- For "Root Directory" field click browse to select android folder in your Cordova project under platforms.
- There will be two things checked (Android project and CordovaLib). leave them checked
- 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.
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.
- Download source zip from http://cordova.io
- Unzip and inside cordova-android folder in README.md file gives these instructions
- In terminal cd into framework folder
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.
android update project -p . -t android-19
Hey, there is the old goodie .jar file with a new name. Add it to libs folder in your android Cordova project.
- Copy cordova-3.3.0.jar file into libs folder of your project (cordova-project-folder/platform/
- Right click project folder and click refresh (to refresh the libs folder if it's empty in eclipse)
- 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.
- Press "Add JARS" and you get a popup window to select jar file.
Error initializing Cordova class not found
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.
There is a build service by Adobe (http://build.phonegap.com) you can use to package your Apps.