Today, I had to create a new PhoneGap app for a client. I was shocked to see that the official docs are still badly incomplete and sometimes just wrong. Anyway, I hope these steps will help others.
I am using PhoneGap 3.2.0 in Mac.
First install Node.js. In Mac, you can install Node.js easily using the GUI installer.
Next, install PhoneGap by running this command.
sudo npm install -g phonegap
Install Android SDK
Download Android SDK for Mac and unzip it somewhere.
PhoneGap 3.2.0 is hardwired to compile with Android SDK Level 17. So, download SDK 17 platform. By the time you are reading this, a newer version of PhoneGap may have come out which may work with a different version of Android. If you are not sure, read on.
Configure Environment Variables
Open ~/.bash_profile. Add these lines. Here <SDK> stands for the folder Android SDK is installed:
Create a Project
From the command line, run:
phonegap create MyProject
This will create a new project in the MyProject folder.
To do a build for Android, go within the MyProject folder. Then run:
phonegap local build android
If there is a problem with the environment variables, or, you don’t have the correct version of Android SDK downloaded, you will see an error message. If all goes well, MyPorject/platforms/android will be created. This folder contains an Eclipse project.
Launch Eclipse.app from <SDK>/eclipse folder.
From the menubar, select File > Import.
Choose Android > Existing Android Code into Workspace.
Choose the MyPorject/platforms/android folder and import the project into Eclipse.
Now, you can run the app from Eclipse using a real device or Android emulator. If you plan on using an emulator, you will need to create one. Right click the project and select Run As > Android Application.
Continue with Development
If you intend to only target Android, then you can do all your development from Eclipse. If you plan on supporting other platforms like iOS, you will need to work with the original project that you had created using the phonegap command. Every time you need to test using an Android device, you will need to do a phone gap build, then launch Eclipse and refresh the project and then run the project.