Phonegap: Building Android apps without eclipse

In this tutorial I will explain how to get a simple Android project up and running using phonegap in a Linux environment without Eclipse. I will assume basic knowledge of Android app development. If you need help with installing the Android SDK, head over to developer.android.com. You should know how to operate a terminal.

Prerequisites

  1. You will need the Android SDK downloaded and unzipped. Also you have to add the tools from the SDK to your PATH environment, e.g. by adding it to your .bashrc file.
  2. Install a target API with the android command. In my case, I will use Android 2.2.3. You can check which targets are installed by executing the command
    android list targets
  3. Install a virtual device or activate debugging in your Android phone
  4. Download and unzip phonegap from www.phonegap.com. (Version 1.4.1 used in tutorial)
  5. Install ant by executing
    sudo apt-get install ant

Creating the project

  1. Open a console and start by creating a new folder for your project.
  2. Locate the folder containing the unzipped phonegap archive. Copy the folders phonegap and .phonegap from /*your-phonegap-folder*/lib/android/example/ to your project folder.
  3. List android targets and note the id of the target you’d like to use for your project. In this case only one target is installed.
    Next, you have to change the config file ./phonegap/config. Choose a name for the package and the main activity. Set the Target to the noted value. Your config file should look something like this:VERSION=1.4.1
    PROJECT_PATH=./project
    PACKAGE=com.antony_neu.TestApp
    ACTIVITY=TestApp
    TARGET=1
  4. Execute ./phonegap/create. This will create your project according to your config file.
  5. The html and script files are located in ./assets/www. An example phonegap file can be found here by default.
  6. Once you are ready to build, fire up an emulator with emulator -avd AVD_NAME and execute ant debug install . The app will be installed to your emulator device and is located in the Apps menu.

Troubleshooting

Q: I update my script files but there are no changes on the device. What is wrong?
A: Try deleting the ./bin folder and run ant again.