Book Image

PhoneGap 3.x Mobile Application Development HOTSHOT

By : Kerri Shotts
Book Image

PhoneGap 3.x Mobile Application Development HOTSHOT

By: Kerri Shotts

Overview of this book

<p>PhoneGap allows you to use your existing knowledge of HTML, CSS, and JavaScript to create useful and exciting mobile applications.<br /><br />This book will present you with 12 exciting projects that will introduce you to the dynamic world of app development in PhoneGap. Starting with their design and following through to their completion, you will develop real-world mobile applications. Each app uses a combination of core PhoneGap technologies, plugins, and various frameworks covering the necessary concepts you can use to create many more great apps for mobile devices.</p>
Table of Contents (21 chapters)
PhoneGap 3.x Mobile Application Development HOTSHOT
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Installing Cordova/PhoneGap


Now that the prerequisites have been taken care of, we can install Cordova/PhoneGap. You can install one or the other, or both, on your system. To help you make that decision, let's go over some of the differences.

It's possible to do mobile app development using only the Cordova command-line interface (CLI). This requires the platform SDKs to be installed and properly configured.

Adding the PhoneGap CLI enables the use of Adobe's remote building capabilities, which means you don't need to have the platform SDKs installed in order to build your app. (There are caveats here; it is best to refer to the PhoneGap Build website at http://build.phonegap.com for more information.)

Installing the PhoneGap CLI will also install the Cordova CLI since it relies on this for most of its functionality. The PhoneGap CLI does not understand the same commands, but since it works with the Cordova CLI, it's possible to use the Cordova CLI when the PhoneGap CLI doesn't offer to do all the same functionality things.

If you intend to do all your development locally, you only need to worry about the Cordova CLI. If you need the flexibility to do remote builds without having platform SDKs installed on your machine, install the PhoneGap CLI.

Getting ready

It is important to note that the installation process requires that your computer be connected to the Internet as we will use npm to download the required packages.

Getting on with it

Based on your earlier decision as to which command line to install, refer to the appropriate section, shown as follows to install Cordova / PhoneGap.

Tip

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Installing Cordova (if not installing PhoneGap)

To begin, open up your terminal or command prompt.

If you're running Mac OS X or Linux, type the following command:

sudo npm install -g cordova

If you're running Windows, make sure you're running as an administrative account and type this:

npm install -g cordova

If prompted, enter your password.

You should see output that looks similar to the following. It won't be exactly the same, but the important thing is that you shouldn't see any errors.

npm http GET https://registry.npmjs.org/cordova
npm http 200 https://registry.npmjs.org/cordova
npm http GET https://registry.npmjs.org/cordova/-/cordova-3.1.0-0.1.0.tgz
npm http 200 https://registry.npmjs.org/cordova/-/cordova-3.1.0-0.1.0.tgz
...
/usr/local/bin/cordova -> /usr/local/lib/node_modules/cordova/bin/cordova
[email protected] /usr/local/lib/node_modules/cordova
├── [email protected]
└── [email protected] ([email protected], [email protected],[email protected], [email protected], [email protected],[email protected], [email protected], [email protected], [email protected],[email protected], [email protected])

To make sure that you can correctly access Cordova from the command line, type this:

cordova --version

You should see output similar to this:

3.1.0-0.1.0

Tip

If your installation of Cordova hangs during the process (perhaps due to a network connectivity issue), just break the process (Ctrl + C) and try again.

Installing PhoneGap (if not installing Cordova)

Open your terminal or command prompt. If you're running Mac OS X or Linux, type this:

sudo npm install -g phonegap

If you're running Windows (as an administrative user), type this:

npm install -g phonegap

If prompted for your password, enter it.

You should see output that looks like this:

npm http GET https://registry.npmjs.org/phonegap
npm http 200 https://registry.npmjs.org/phonegap
npm http GET https://registry.npmjs.org/phonegap/-/phonegap-3.1.0-0.15.0.tgz
npm http 200 https://registry.npmjs.org/phonegap/-/phonegap-3.1.0-0.15.0.tgz
npm http GET https://registry.npmjs.org/node-static/0.7.0
npm http GET https://registry.npmjs.org/phonegap-build/0.8.4
...
/usr/local/bin/phonegap -> /usr/local/lib/node_modules/phonegap/bin/phonegap.js
[email protected] /usr/local/lib/node_modules/phonegap
├── [email protected]
└── [email protected] ([email protected], [email protected],[email protected], [email protected], [email protected],[email protected], [email protected], [email protected], [email protected],[email protected], [email protected], [email protected], [email protected],[email protected], [email protected], [email protected], [email protected])

When complete, test whether you can access PhoneGap by typing this:

phonegap --version

You should see output similar to this:

3.1.0-0.15.0

Tip

As with installing Cordova, if your installation hangs, just break it (Ctrl + C) and redo the installation.

What did we do?

In this section, we successfully installed the Cordova CLI and, if you chose to, the PhoneGap CLI on your machine. Your machine is now ready for Cordova/PhoneGap development.

What else do I need to know?

It's possible that you'll see various errors or notices in the output of the install process. Generally, WARN and 304 notifications aren't cause for alarm, but if you see anything more serious, you may need to retry the install or address the underlying cause.

It's also possible that if your platform SDK is improperly set up, you'll get errors during the installation process. These should indicate the platform SDK in question.