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.
- 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.
- Install a target API with the
androidcommand. In my case, I will use Android 2.2.3. You can check which targets are installed by executing the command
android list targets
- Install a virtual device or activate debugging in your Android phone
- Download and unzip phonegap from www.phonegap.com. (Version 1.4.1 used in tutorial)
- Install ant by executing
sudo apt-get install ant
Creating the project
- Open a console and start by creating a new folder for your project.
- 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.
- 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:
- Execute ./phonegap/create. This will create your project according to your config file.
- The html and script files are located in ./assets/www. An example phonegap file can be found here by default.
- Once you are ready to build, fire up an emulator with
emulator -avd AVD_NAMEand execute
ant debug install. The app will be installed to your emulator device and is located in the Apps menu.
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.