Getting Started With Phonegap: Phonegap and Apache Cordova

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

Getting Started with PhoneGap

1
PhoneGap is an application framework that enables you to build native
applications using HTML and JavaScript. Think of PhoneGap as a web view
container that is 100% width and 100% height, with a JavaScript programming
interface that allows you to access operating system features. The main issue
developers used to face with Apache Cordova/PhoneGap was the setup of the
development environment and the dependencies with other IDEs. Since version
2.x, however, things have changed dramatically and now the setup is pretty
straightforward. This chapter covers setting up your development environment.

In this chapter we will:

‹ Get an overview of the history of Apache Cordova/PhoneGap


‹ Learn how to configure your development environment configuring all
the dependencies
‹ Learn how to create a new project using Eclipse, Xcode, and Visual Studio
‹ Learn how to create a common code base without using the CLI (Command Line
Interface) tool released with the version 2.0

PhoneGap and Apache Cordova


PhoneGap was originally developed by Nitobi, a company acquired by Adobe in 2011.
After it was acquired, Nitobi donated the PhoneGap code base to the Apache Software
Foundation (ASF) under the project name Cordova, which is the name of the street in
Vancouver where Nitobi's offices were located and where the company created the first
version of the framework.
Getting Started with PhoneGap

One of biggest advantages of moving the code base to the ASF is that big organizations can
easily contribute to the project (many companies are not only comfortable with the Apache
organization and license, but already have a Contributor License Agreement with Apache);
furthermore, the project is now under an open and transparent governance: its community!

PhoneGap is a free and open licensed distribution of Apache Cordova. Picture Cordova to
be the engine upon which PhoneGap and its related services (debug, emulate and build
services) are built. For existing PhoneGap developers nothing has changed; but for those
who are interested in contributing to the project, Apache Cordova is a great chance to join
a vibrant open source community.

Adobe continues to play a major role in the project, investing in its ongoing development,
and the company decided to keep the PhoneGap name to describe its own distribution of
the Cordova project. Other contributors to the Apache Cordova project includes Google,
RIM, Microsoft, IBM, Nokia, Intel, and Hewlett-Packard.

The evolution of PhoneGap from 1.4 to 3.x


PhoneGap has evolved very quickly since January 2012, with ten releases in the first nine
months of 2012. Projects such as NodeJS and Gnome, among others, use odd MINOR
version numbers to denote development releases. It's a very good practice that tells
developers whether a release has major or minor improvements.

Apache Cordova follows the guidelines defined in the Semantic Versioning specification
(more information is available at http://semver.org/), which seeks to address one of
a developer's nightmares: dependency hell. The Semantic Versioning specification codifies
the long-standing de facto version schema of X.Y.Z where X denotes MAJOR changes, Y
represents MINOR updates, and Z is a PATCH to the minor update stream.

Since the 1.4 release, the project has been known as Apache Cordova. This release is
generally considered the first stable release of the framework, with a fairly complete and
up-to-date documentation. The 1.5 release fixed a long list of bugs, but the initial reaction
of the community was not very favorable because the documentation was outdated and
some changes to the main files caused broken build issues to apps developed with earlier
releases. The 1.6 release brought some improvements to the plugin architecture, the Camera
and Compass APIs, and the project template files. As is often the case with a maturing
community, the release was not perfect but there was a significant improvement in the
overall quality compared to the previous release. The 1.7 and 1.8 releases were bug fixes and
added support for Bada 2.0. The community reaction was positive also because of the speed
of the releases. The 1.9 release addressed even more bug fixes and added support for the
new features of the iOS and Android platforms.

[8]
Chapter 1

Apache Cordova 2.x added the following features and support:

‹ The definition of a unique JavaScript file to use across all platforms thanks to the
unification of the JavaScript layer of the Cordova application framework
‹ The introduction of a command line tool (CLI) through which common operations,
such as project creation, debug, and emulation, can be performed in a standard way
(Android, iOS, and BlackBerry)
‹ The capability to embed PhoneGap applications into larger native iOS and Android
applications using Cordova WebView
‹ Support for the Windows phone platform
‹ The porting of the Web Inspector Remote (Weinre) to nodejs and the introduction
of a node module that facilitates installation using Node package manager (npm)
‹ An improved plugin documentation and support thanks to a plugman Node.js
application able to install compliant plugins
‹ Several improvements to the process of creating iOS apps
‹ The introduction of the long-awaited InAppBrowser API (formerly called
ChildBrowser)
‹ The standardization of the commands available for each platform (i.e., build, run,
and so on)
‹ Full support for Windows Phone 8

With the 2.x release, Apache Cordova and PhoneGap have become a mature, stable, and
powerful tool in the mobile developer's toolkit. The upcoming PhoneGap 3.x will no longer
support BlackBerry 7 and will add support for Ubuntu and Firefox OS. Since PhoneGap 3.x
the APIs work like plugins and can be installed and uninstalled using the updated cordova
cli utility, enabling the PhoneGap core to be slim and better performing. PhoneGap 3.x
also comes with a better set of command-line tools; for instance, the phonegap npm
module allows you to build your app using the command line and the online PhoneGap
Build service. For a good overview of the major changes in PhoneGap 3.x refer to the blog
post at http://phonegap.com/blog/2013/06/20/coming-soon-phonegap30/.

A note about operating systems


We touched on this in the preface but it's worth emphasizing again: PhoneGap plays by the
rules. If a vendor releases an SDK for a single operating system only, then you will have to use
that OS to build and deploy your applications.

[9]
Chapter 1

A note about the command-line tool


Across this book you will widely use command-line tool, if you are on a Mac or on a
Linux machine the commands you can type in the tool are almost the same. On Mac the
command-line tool is named Terminal and you can find it by navigating to Applications
| Utilities | Terminal. On Linux you refer again to the command-line tool with the word
"Terminal" but its location varies accordingly to the Linux distribution you are using. In
Gnome, the classic desktop environment for Ubuntu 11.04, you can find the Terminal by
navigating to Applications | Accessories | Terminal. In Xfce you can find the Terminal by
navigating to Applications | System | Terminal.

On a Windows machine the command-line tool is named MS-DOS prompt and can be
opened by typing cmd and pressing Enter, in the start menu. The commands syntax is
different from the Mac or Linux one, the most relevant differences are summarized in
the following table:

Command Terminal MS-DOS prompt


Copy Files cp copy
Edit text files vi edit
Compare files diff fc
Browse files ls dir
Clear screen clear cls
Create a symbolic link ln mklink

Installing PhoneGap
The installation process of PhoneGap has been confusing for a long time because there were
a lot of dependencies. These dependencies were due to the fact that in order to compile an
app for different platforms, you not only have to have the platform-specific SDKs but also
the platform-specific tool: in order to build for Android Eclipse, IntelliJ, or Android Studio is
needed; to build for iOS Xcode is needed, and so on.

With Apache Cordova 2.x and 3 both the installation process and setting up your
development environment have become much easier. You can now use the build services
provided by Adobe, plus Cordova 2.x and 3 ships with a set of command-line tools that
make it easier to develop cross-platform applications. Installing PhoneGap is now as easy as
downloading the latest distribution from the website and unzip the package—you'll get the
following folders:
|-doc
|-lib
|---android

[ 11 ]

You might also like