2. Installing the Cordova and PhoneGap Frameworks

The traditional way of installing Apache Cordova or Adobe PhoneGap is to download the framework’s files and optionally (depending on which version of the framework you download) perform some additional configuration. Although Apache Cordova and Adobe PhoneGap are, at their core, very similar (the differences between the two are described in Chapter 1), the steps performed to get your development environment ready to work with the frameworks are different.

In this chapter, I walk you through the process of downloading and setting up the framework. Subsequent chapters illustrate how to install and use the command-line tools as well as how to set up and use development environments for several of the Cordova-supported mobile device platforms.


Note

You don’t really need to do the stuff in this chapter if you plan to use the Cordova CLI or the PhoneGap Build service (described in Chapter 11, “Using PhoneGap Build”) exclusively for your Cordova development projects. However, there’s still value in having the framework installed so you can have a local copy of the documentation or source code.


Installing Apache Cordova

Apache Cordova is an open source project, so the framework files are a free download from the Apache Cordova project website. Point your browser of choice to http://cordova.io. You will be presented with a page similar to the one shown in Figure 2.1. The big download link at the middle-right side of the page takes you directly to the download section of the page shown in Figure 2.2.

Image

Figure 2.1 Apache Cordova Project Home Page

Image

Figure 2.2 Apache Cordova Current Version Download Folder

Click on the source.zip link to download the most recent version of the Cordova framework. You will be taken to an Apache download page, which will allow you to select the mirror from which to perform the software download. To download an earlier version of the framework, click the archive link shown at the bottom of Figure 2.2. The website will open the archives page shown in Figure 2.3.

Image

Figure 2.3 Cordova Archives

The listing shows the framework download file (the .zip file shown in the figure) plus some output files from cryptographic hash functions used to help identify whether the .zip file has been modified. As you can see from the screenshot in Figure 2.2, the file access is provided over an HTTPS connection, so it is not likely that your download can be intercepted and a bogus file substituted. However, if you’re appropriately paranoid, you can validate the source files using the keys provided. The .sha file is generated using the Secure Hash Algorithm (SHA), the .md5 file is generated using Message Digest Algorithm-5 (MD5), and the .asc file contains the PGP signature for the file.

If downloading the file using Safari on later versions of Macintosh OS X, the files will be automatically extracted after they download. On Windows, or if you are using a different browser on your Macintosh, you’ll have to manually extract the files.


Note

The Cordova framework .zip file no longer contains files for several of the supported mobile device platforms, such as bada, Tizen, Symbian, webOS, and even Windows Phone 7. Even though the platforms are still supported, the files for those particular OSs were removed after the Cordova 2.5 release. You will have to manually download the additional platforms if needed.

A quick search on Google told me I could find the Cordova files for bada at https://github.com/apache/cordova-bada, for Tizen at https://github.com/apache/cordova-tizen, and for webOs at https://github.com/apache/cordova-webos.


There is no installer for the Apache Cordova files; once extracted, the Cordova download will expand to the file listing shown in Figure 2.4. As you can see, the download includes a separate .zip file for each of the mobile device platforms supported by Cordova plus some additional files, which are described in Table 2.1.

Image

Figure 2.4 Apache Cordova Download File Listing

Image
Image

Table 2.1 Cordova Archive .zip File: List of Additional .zip Files

In order to build applications locally for each mobile device platform, you need to extract the .zip file(s) for each platform. Each .zip file contains a text file called readme.md; you can open the file in any standard text editor and quickly learn what the files in the folder are used for. In most cases, there are simply instructions for how to use the files, but in some cases, such as with the Android Cordova implementation, there are additional instructions you will need to follow to complete the setup.


Tip

On Macintosh, an .md file will open automatically in the TextEdit application; just double-click on it, and it opens. The default Windows text editor (notepad.exe) doesn’t understand the .md file extension, so you can’t just double-click on the file in Windows Explorer to open it. You must manually open the file from Notepad, or you may want to use a third-party text editor such as Notepad++ (http://notepad-plus-plus.org), which registers a right-click menu item that allows you to right-click on an .md file and edit it directly in Notepad++.

An .md file is a text file created using one of the dialects of the Markdown language. Markdown is essentially a plain text format that can be easily converted to HTML.


To configure development environments for the different supported mobile device platforms, you need to install the platform’s native software development kit (SDK) or integrated development environments (IDE). For some platforms, you may also need additional tools such as Java, Ant, make, and Cygwin. Except for the cost of joining the appropriate developer programs, pretty much all of the tools you need for local Cordova development are free.

Ant-Based Command-Line Interface

As mentioned in Chapter 1, Cordova 3.0 added a new suite of command-line tools to the framework. When you expand all of the Cordova framework files for the different mobile device platforms, you may run across information in the readme.md about using Apache Ant (http://ant.apache.org) to create new Cordova projects and to debug Cordova applications in a device simulator or emulator.

In older versions of Cordova, you had IDE tools (like plugins for Xcode for iOS and Eclipse for Android) plus the CLI at your disposal. Unfortunately, the Ant-based CLI was implemented inconsistently across the different mobile platforms, so you couldn’t use it everywhere, and each implementation was in a different place, so you didn’t have a single tool you could use anywhere. The Node.js-based CLI (described in Chapter 3) replaces the Ant-based process and is implemented more consistently across platforms.

For that reason, I don’t cover the Ant-based tools in this book and instead focus on the Node.js-based tools. Over time, all of the Ant-based tools should be migrated to Node.js.

Installing Adobe PhoneGap

The installation process for Adobe PhoneGap is a little different. To access the installation instructions and archives, point your browser of choice to www.phonegap.com. You will be presented with a page similar to the one shown in Figure 2.5.

Image

Figure 2.5 PhoneGap Installation Instructions

Beginning with PhoneGap 3.0, Adobe stopped making a specific download package and instead does everything through a Node.js package. So, when you click the Download PhoneGap button shown in the figure, you will be taken to the installation instructions shown in Figure 2.6.

Image

Figure 2.6 PhoneGap Downloads Page

Installation is similar to what is described in greater detail in Chapter 3. To install PhoneGap, the PhoneGap website tells you that you simply have to install NodeJS (www.nodejs.org), then open a command prompt and type the following command:

npm install –g phonegap

Experience tells me that there’s a lot more to it, so jump to the next chapter to read about all of the requirements and issues you will face during the installation and afterwards.


Tip

The PhoneGap documentation is essentially (most likely exactly—I didn’t check) the same as the Cordova documentation, so there’s little need to check both sites for information. I used the PhoneGap documentation only when I was looking for information about some feature that is unique to the PhoneGap implementation of Apache Cordova.


If you’re looking for an older version of PhoneGap, you can scroll down on the page shown in Figure 2.6 and access the downloads for most earlier versions of the framework.

Wrap-Up

In this chapter, I showed you how to download and install the Apache Cordova and Adobe PhoneGap frameworks. We can’t really do anything yet with what we have installed, but in the chapters that follow, I show you how to develop and test your Cordova applications plus how to configure and use a local development environment for several of the most popular mobile device platforms. Immediately following those chapters, I show you how to use the PhoneGap Build service to help dramatically simplify all of this work.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset