Getting started with Phonegap/Cordova

Install Prerequisites and Tools

The very first step is to install all prerequisites and tools, these are:

  1. Install the Java Development Kit: Download the Java Development Kit and install it.
  2. If on windows, Set up the JAVA_HOME system variable:
    1. Select Start menu > Computer > System Properties > Advanced System Properties.
    2. Open Advanced tab > Environment Variables.
    3. Add a new system variable JAVA_HOME that points to your JDK folder, for example C:\Program Files\Java\jdk1.7.0_21.
  3. Add the JAVA_HOME bin path system variable to the PATH variable:
    1. Select Start menu > Computer > System Properties > Advanced System Properties.
    2. Open Advanced tab > Environment Variables.
    3. Select the PATH system variable
    4. Click edit
    5. Add the following to the end of the variable: ";%JAVA_HOME%\bin"
  4. Ensure you have the android sdk tools and platform-tools folder in your PATH variable
    1. Select Start menu > Computer > System Properties > Advanced System Properties.
    2. Open Advanced tab > Environment Variables.
    3. Select the PATH system variable
    4. Click edit
    5. Add the following to the end of the variable: ";%Android SDK%\platform-tools;%Android SDK%\tools" where %Android SDK% is the path to your android sdk location, normally "C:\Program Files (x86)\Android\android-studio\sdk"
  5. Download and install NodeJS from the NodeJS Website
  6. Open Terminal (Mac) or a Command window (Windows), and type the following command to install the Cordova CLI:
    npm install -g cordova
    or on a Mac:
    sudo npm install -g cordova

Create Cordova project

Navigate to a directory where you store projects on your system. Create a project called "workshop":

cordova create workshop com.yourname.workshop Workshop
Navigate to the project directory:
cd workshop

Add the platforms you want to support. For example, to add support for iOS and Android, type:
cordova platforms add ios cordova platforms add android
Make sure you are in the "workshop" directory, and add basic plugins to your projects:
cordova plugin add org.apache.cordova.device
cordova plugin add org.apache.cordova.console

Building a Cordova Project

iOS

You need the iOS SDK installed on your computer to build an iOS version of your application using the steps below.
cordova build ios
The project is built in the workshop/platforms/ios folder. Double-click Workshop.xcodeproj to open the project in XCode, and run it in the emulator or on your device. You can also run the application in the iOS emulator directly from the command line. First install ios-sim:
sudo npm install -g ios-sim
Then run the application in the iOS emulator:
cordova emulate ios

Android

You need the Android SDK installed on your computer to build an Android version of your application using the steps below. To build the project in the workshop/platforms/android folder and run it on an Android device connected to your computer using a USB cable, type:
cordova run android
To build the project in the workshop/platforms/android folder and run it in the Android emulator, type:
cordova emulate android

Import project in Eclipse

Use the cordova utility to set up a new project, as described in The Cordova The Command-Line Interface. For example, in a source-code directory:
cordova create hello com.example.hello "HelloWorld" cd hello cordova platform add android cordova build

Once created, you can use the Eclipse that comes along with the Android SDK to modify it:

Launch the Eclipse application. Select the New Project menu item.

Choose Android Project from Existing Code from the resulting dialog box, and press Next:

Navigate to hello, or whichever directory you created for the project, then to the platforms/android subdirectory.

Make sure both hello and hello-CordovaLib projects are selected to be imported. The hello-CordovaLib project is needed as of Cordova 3.3.0 because Cordova is now used as an Android Library instead of a .jar file.

Press Finish.

Once the Eclipse window opens, a red X may appear to indicate unresolved problems. If so, follow these additional steps:

Right-click on the project directory. In the resulting Properties dialog, select Android from the navigation pane. For the project build target, select the highest Android API level you have installed. Click OK. Select Clean from the Project menu.

This should correct all the errors in the project.

Deploy to Emulator

You can use the cordova utility to run an app in an emulator, or you can run it within the SDK. Either way, the SDK must first be configured to display at least one device. To do so, use the Android SDK Manager, a Java application that runs separately from Eclipse. There are two ways to open it: Run android on the command line.

From within Eclipse, press this toolbar icon:

Once open, the Android SDK Manager displays various runtime libraries:

To open the emulator as a separate application, select the AVD and press Start. It launches much as it would on the device, with additional controls available for hardware buttons At this point you can use the cordova utility to deploy the application to the emulator from the command line:

$ cordova emulate android
If instead you work within Eclipse, right-click the project and choose Run As → Android Application. You may be asked to specify an AVD if none are already open.

Known Errors

When exporting as akp you get

conversion to dalvik format failed with error 1
Solution Project → deactiviate "Build Automatically" → Export again

R.java has been motified Passiert wenn man corodova build
happens when you build the project with die corodva CLI and have it opened in eclipse. Solution: Refresh project in eclipse