- Bring up a terminal window (Ctrl+Alt+T), and type sudo -s to sign in to a root session.
- Do a apt-get update and apt-get upgrade, just because it’s good practice.
- Copy the latest link to the node.js Linux package from this link.
- Change directory to /tmp: cd /tmp
- Type wget <URL of node.js package from Step #3> to download the latest version.
- Unzip the tarball by entering tar -zxvf node-*.tar.gz.
- Remove the tarball by entering rm node-*.tar.gz.
- Move the resulting directory somewhere friendly. This tutorial will use /usr/lib/nodejs as the destination. (If all goes well, you should see “bin” and “node_module” directories [amongst others] in the /usr/lib/nodejs path.) To do this, type mv node-* /usr/lib/nodejs.
- Change directory to /usr/bin: cd /usr/bin
- Create a symlink for the node binary: ln -s /usr/lib/nodejs/bin/node ./node
- Create a symlink for the npm binary: ln -s /usr/lib/nodejs/lib/node_modules/npm/cli.js ./npm
- Now, we need to download git and some libraries that phonegap is dependent upon. If you are running the x86_64 version of 13.10, type apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 lib32stdc++6 git -y. If you are running the i386 version, type apt-get install libz1 libncurses5 libbz2-1.0 libstdc++6 git -y.
- With any luck, we’re ready to start the PhoneGap install. Type npm install -g phonegap.
- Exit the root shell by typing exit. This is quite important for various permission-based reasons.
- Go back to your home directory by typing: cd ~.
- Run phonegap. You should now see the manual page.
- Create an empty project by typing phonegap create helloWorld
- Navigate into the project’s directory: cd ~/helloWor
- Build the program by entering phonegap build android -V
Well, kind of. As you will see, once you run the build command in PhoneGap, it will ask you to login with an Adobe ID account (hit CTRL-C to break out of this, if you wish). This is necessary if you want to use PhoneGap’s cloud compilation services – which is probably a good idea if you just want a one-stop solution for producing an app on multiple operating systems. Accounts to their cloud compilation service range from free (1 private project with unlimited open source projects) to $10/month to expensive, but it is definitely the easiest way to date to mass-produce apps for multiple platforms. The drawback to this is that all of your code is uploaded to Adobe’s cloud (and Adobe’s authentication servers just recently got hacked)… just food for thought.
If you want to test your PhoneGap in a more secure environment, we can do so by building the packages locally and using the freely available Android emulator for testing. I recommend this method since it does not require you to register with Adobe in order to run PhoneGap API applications.
After completing steps #1 – 14 above, perform the following steps:
- Type sudo apt-get install openjdk-7-jdk ant -y to install OpenJDK and Ant, both required by Android’s SDK.
- Go back into /tmp to download the Android SDK: cd /tmp
- Type wget <URL of Android SDK found here> to download the Android SDK ZIP. This is quite large (~450MB for the x86_64 version).
- Type unzip adt-bundle-linux-*.zip to unzip the file.
- Type rm adt-bundle-linux-*.zip to delete the ZIP. It is no longer needed.
- Now, we need to move the extracted files to a more suitable location. Type sudo mv adt-bundle-linux-* /usr/lib/android-sdk, and enter in the password for your account if prompted.
- We now need to update our PATH environment variable in the bash configuration file, so that PhoneGap can call the Android emulator. Type nano ~/.bashrc.
- Navigate to the end of the file (press the “Page Down” key multiple times until the cursor is at the bottom). Type export PATH=$PATH:/usr/lib/android-sdk/sdk/tools:/usr/lib/android-sdk/sdk/platform-tools on a new line at the very end of the file, and press CTRL+X. A dialog at the bottom of the screen will ask you if you want to overwrite the existing .bashrc file. Type “Y” and hit the ENTER key to confirm.
- Type source ~/.bashrc to refresh your bash configuration.
- You should now be able to type in android and see the “Android SDK Manager” window. Make sure that the checkboxes next to the “Tools” folder (at the top of the list) and the “Android 4.2 (API 17)” are checked, then click on the “Install # packages…” button below the list (where # is a number). We are skipping Android 4.3/API 18 group as PhoneGap does not support it yet (and in fact, breaks the PhoneGap build process).
- Read through the EULA for the Android tools, and accept them. Click “Install”. Wait for everything to download and install. This will download about ~400 MB of packages.
- Once finished, remain in Android SDK Manager. Click on the “Tools” menu, and select the “Manage AVDs” option.
- Click on the “New” button on the right-hand side of the screen, and give the AVD a name. Select “Nexus S” as the Device, “Android 4.2.2 (API 17)” for the Target (IMPORTANT), and “ARM” as the CPU. If your system can handle it, I would give the AVD at least 512 MB of RAM under “Memory Options” to speed things along. Similarly, give the AVD a SD card of at least 64 MB. Click “OK”.
- Select the AVD in the list, and click the “Start…” button on the right-hand side of the screen. Click “Launch” on the popup window.
- If you start to see the emulator pop up, and see an “Android” splash screen, you’re all set. Close out of the emulator, the Android Virtual Device Manager, and the Android SDK Manager.
- Returning to the shell, type cd ~/helloWorld to navigate to your PhoneGap project.
- Finally, type phonegap run android -V. If all went well, you will see the Android emulator pop up after a minute or so, and install your PhoneGap project after a few more minutes of waiting. Just to note: you may have to unlock the screen and go through Android’s tutorial before you can get to your project the first time. It is a good idea to keep the emulator running while building new revisions of a PhoneGap project, as it only takes a few seconds to push a new version of the resulting APK to it (as opposed to the minutes it takes to cold-boot).
And that’s all there is to it.