Building Cross Platform Mobile Apps with Adobe PhoneGap

Cross-platform compatibility is a challenge for software developers. One must balance the desire for maximum reach with the ability to bring a product quickly to market. In terms of mobile devices, the issue involves deciding which platform to build for–specifically, whether to focus on iOS or Android–as these two platforms dominate the mobile arena, and will continue to do so in the foreseeable future.

Applications such as PhoneGap allow one to target both Apple and Android, as well as Windows, using common web development languages. Developers can now build feature-rich mobile apps with native functionality using HTML/CSS/JavaScript, as opposed to learning and using device-specific languages like Objective-C or Java. This effectively enables mobile application developers to "write-once, run everywhere," saving them the effort of tackling each platform's respective learning curve.

Building Mobile Web Apps with HTML, CSS and JavaScript

For a time, the HTML/CSS/JavaScript triumvirate by itself was the solution to mobile cross-platform compatibility, as building for the mobile web browser effectively leapfrogs the iOS/Android argument. Instead of having to download and install an iOS or Android version of an application, users would access it universally on their mobile browser.

JavaScript libraries can enable touch-optimized functionality and interactivity, while HTML5 and CSS-rendering ensure a mobile-friendly user experience. Furthermore, libraries such as Phaser enable developers to create visually stunning games and graphic applications. Similarly, web drawing libraries such as Paper.js and Processing.js allow developers to incorporate complex vector graphics and animations into their applications using JavaScript frameworks running on top of the HTML5 Canvas -- technology meets pretty pictures, just like that.

Building HTML/CSS/JavaScript-based mobile web apps for in-browser use, however, exposes occasional drawbacks–mainly in inconsistent or lost functionality. For example, low-level access to the address book, camera, and location-based services is in many cases unavailable to the mobile browser. By targeting the mobile web, the gain of cross-platform usability is tempered by the loss of custom behavior native to iOS or Android.

The PhoneGap Solution

With PhoneGap, developers use HTML/CSS/JavaScript to build hybrid mobile applications that output to iOS, Android and Windows. It is achieved by wrapping the web application in a native container. This effectively solves the problem of mobile web browser generality while extending the same benefits of common language formats to the developer. Applications built with the PhoneGap application framework are developed in the same fashion as mobile web apps, with the additional benefit that they have access to native device APIs. Furthermore, they can be packaged and distributed via Apple's App store or Google Play.

While in-depth, step-by-step directions for building apps with PhoneGap are beyond the scope of this discussion, tutorials can be found on the PhoneGap blog to help in this regard. For the sake of brevity, the steps to building a hybrid mobile app with PhoneGap for the first time can be summarized as follows: 1) designing the app, 2) coding the app, 3) testing the app, and 4) distributing the app.

1) Designing the App

At this initial phase of the project, designs and wireframes are composed within Adobe Photoshop or a similar graphics or prototyping application. The goal is to map out the functionality and general look/feel of your app, allowing the developer to understand the application’s logic and interface from a user's perspective.

2) Coding the App

The procedures for installing PhoneGap and configuring your development environment will vary depending on which platform you intend to target. For iOS, you will need to download and install XCode and the iOS SDK–this assumes that you've signed up for the Apple Developer Program and have the appropriate credentials to their developer portal. For Android, downloading the Eclipse IDE will suffice. Once PhoneGap and your IDE are installed, the development and coding is more or less the same as building a standard web application. The folder structure created by PhoneGap is self-explanatory, with the "www" folder being the root directory for the web app. CSS, images, and JavaScript libraries are stored in their folders under "assets" (e.g.-- assets/css). Another option is to avoid the need for all of this setting up and just use PhoneGap Build. You code your app like a normal web application, then, instead of compiling the app on your computer, you can do it on the cloud.

3) Testing the App

Once you've coded your application, you can test and debug your application by either using the iOS simulator within XCode, or the Ripple PhoneGap Emulator. This will be dependent on your operating system and/or target development platform. If you decided not to install PhoneGap on your computer, your code must be uploaded to PhoneGap Build-- PhoneGap's cloud-based compilation service. PhoneGap Build takes the HTML/CSS/JS files of the application (archived in a ZIP file) and sends back the application, ready for testing. You should install this application on a physical device in order to test it.

4) Distributing the App

Once you are happy with the app, you need to build distributable versions. Again, the process for doing this varies based on which platform you are targeting, but it’s made easy with the use of PhoneGap Build. You simply provide some platform developer information/credentials and security information and Build will take care of the rest, leaving you with applications that are ready to upload to the app stores.

Summary

In short, PhoneGap is a great tool for developers to quickly build hybrid, multi-platform mobile apps. By eliminating the need to learn Objective-C or Java, PhoneGap allows web developers to use the HTML/CSS/JavaScript languages they already know to build mobile apps. Since iOS and Android development both involve a steep learning curve, these HTML5 tools drastically cut down on development efforts and time to market.

You can learn to be a web developer with Code Avengers. We have courses that cover HTML/CSS, JavaScript, and web app development. Click on the link below to get started.

View Web Dev outline