Getting Started With Phonegap: Phonegap and Apache Cordova
Getting Started With Phonegap: Phonegap and Apache Cordova
Getting Started With Phonegap: Phonegap and Apache Cordova
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.
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.
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
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/.
[9]
Chapter 1
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:
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 ]