Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • PhoneGap By Example
  • Toc
  • feedback
PhoneGap By Example

PhoneGap By Example

By : Andrew Kovalenko
close
PhoneGap By Example

PhoneGap By Example

By: Andrew Kovalenko

Overview of this book

PhoneGap is a free and open source framework that allows you to create mobile apps using standardized web APIs for the platforms you care about. It is one of the first and fastest spreading tools to develop hybrid applications using CSS, JavaScript, and HTML, without losing the advantages of native applications. If you are already a web developer, this book will provide you with the skills you need to create, customize, test, and deploy hybrid mobile applications. Starting from the beginning, this book will cover how to set up your PhoneGap development environment, add mobile web frameworks and plugins, design and customize the application layout, and utilize the embedded features of the PhoneGap framework. By working through the steps in each chapter, you will quickly master a variety of mobile applications with totally different approaches. You will then learn how to develop a PhoneGap plugin with native interfaces for iOS and Android, as well as common approaches to test PhoneGap applications. With ample screenshots that show you how to build a phenomenal application, PhoneGap by Example will ensure your success with this cutting-edge mobile development framework for hybrid applications.
Table of Contents (12 chapters)
close
11
Index

Downloading and installing

When working with older versions of PhoneGap, we have to make a lot of detailed settings of the environment in order to run the application. However, with the newer versions, starting from 5.0.0, this procedure becomes easier. Before installing PhoneGap, we need to install Node.js, because it is easier to install PhoneGap CLI as a ready-to-use NPM package without compiling it from source codes. And NPM is a utility of Node.js.

Tip

Node.js is a platform built on Chrome's JavaScript runtime. It was built as a tool for fast and scalable network applications. The main feature of the framework is an event-driven, non-blocking I/O model. For now, it is mainly used on server side in the same way as PHP, Ruby, or others. However, it is very popular and spreading fast nowadays.

There are several ways to install Node.js, but I will describe only two of them.

Installing Node.js on Mac

We will see how to install Node.js from the official website and with Homebrew.

Installing Node.js from the official website

To install Node.js, you can download a pre-compiled binary package, which makes for a nice and easy installation. Follow these steps:

  1. Head over to http://nodejs.org/ and click on the INSTALL button to download the latest package:
    Installing Node.js from the official website
  2. Install the package by following along. You will then be directed to install Node.js and NPM (Node Package Manager), which facilitates installs of additional packages for Node.js:
    Installing Node.js from the official website
  3. At the end of the install, you will be prompted to make sure that /usr/local/bin is in your path. Double-check that you have it by running in the terminal using this command:
    $ echo $PATH

    If not, add it in either .bash_profile or .bashrc in your home directory.

  4. After the installation, check whether it is OK by entering the following command in the command line node, which will open a Node.js JavaScript session:
    $ node
    > console.log('PhoneGap by Example');
    PhoneGap by Example
    undefined
    
  5. To exit the Node.js session, just hit control + c twice. And we are done with the first method of Node.js installation.

Installing Node.js with Homebrew

Another good way to install Node.js is using Homebrew.

Homebrew (http://github.com/mxcl/homebrew) is the package manager that Apple forgot. Written in Ruby, it allows you to quickly and easily compile software on your Mac.

To install Homebrew (http://brew.sh/), follow these steps:

  1. Run the following command on the console:
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    

    Tip

    The script explains what it will do and then pauses before it does it. It might require you to execute sudo and enter your root password. You should wait for a while to download and install all the components.

  2. Once the installation is complete, you will receive a Successful Installation message:
    ==> Installation successful!
    ==> Next steps
    Run `brew doctor` before you install anything
    Run `brew help` to get started
    
  3. Once Homebrew is installed, you can go ahead and install Node.js:
    brew install node
    

It might require root access from you as well. And that is it. Node.js is installed now. It is pretty easy, right?

Installing Node.js on Windows

  1. Download the installer from https://nodejs.org/download/.
  2. Run the installer.
  3. Follow the steps in the installer. One default option is to install NPM and another is to add Node.js to our path:
    Installing Node.js on Windows
  4. Test Node.js. Just open the Windows command prompt and type node –v. This should print a version number.
  5. Test NPM. Type npm -v in the terminal. This should print NPM's version number.

Installing Node.js on Linux

To install Node.js on Linux, we should be familiar with the terminal as well. First of all, we need to install dependencies. Follow these steps:

  1. Installing Ruby and GCC:
    • For Ubuntu or Debian:
      sudo apt-get install build-essential curl git m4 ruby texinfo libbz2-dev libcurl4-openssl-dev libexpat-dev libncurses-dev zlib1g-dev
      
    • For Fedora:
      sudo yum groupinstall 'Development Tools' && sudo yum install curl git m4 ruby texinfo bzip2-devel curl-devel expat-devel ncurses-devel zlib-devel
      
  2. Installing Homebrew:
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/linuxbrew/go/install)"
    

After that, we need to add the following three lines to .bashrc or .zshrc:

export PATH="$HOME/.linuxbrew/bin:$PATH"
export MANPATH="$HOME/.linuxbrew/share/man:$MANPATH"
export INFOPATH="$HOME/.linuxbrew/share/info:$INFOPATH"

So, all the prerequisites are done, and we can install Node.js now. There are only two steps left to follow:

  1. Open the terminal and type brew install node.
  2. Wait until Homebrew finishes installation.

Now, we can test Node.js and NPM by running node -v and npm -v in the terminal accordingly.

Tip

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. 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.

bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete