Cordova represents an enormous potential benefit for mobile and web programmers alike. In this video, Tom Duffy shows you what Cordova does, what it doesn't do, and why you should be using it to build your next mobile app.
- [Lecturer] Now is a good time to talk about what Cordova does and doesn't do so that you understand the value Cordova offers developers. Sometimes it's easier to start with what something doesn't do to explain how valuable it is. First, Cordova is not an editor, it cannot help you create the files nor the code needed for your app to function, you'll need another tool to create those. In fact, Cordova has no user interface at all. Second, Cordova is not an integrated development environment, a superset of an editor. An IDE usually includes an editor along with debugging tools.
So what does Cordova do then? First, Cordova converts an existing web application into a native mobile app for supported platforms. The simple truth is that users want native apps, they want to shop in an app store or a marketplace, and they want the ease of updating apps via their phones, not over the web. Cordova produces native apps that behave exactly like any other native app. Second, Cordova uses plugins that tie your web app into a mobile device's native capabilities. Your web app will have access to all of the things any platform-specific native app has, including things like sensors for GPS and the accelerometer, services, SMS, media, contacts, input and output via texts, dialogs and the camera, and even graphics and more.
Third, Cordova lets you develop your app using web technologies for deployment on many platforms. Developing apps for the major smartphone platforms can be frustrating, you need to be proficient in multiple object-oriented programming languages, master various different IDEs and maintain different code bases for supported platforms. Instead, Cordova allows you to maintain a single code base, targeting multiple platforms. At its heart, Cordova is really a build tool, as input it takes a web application and it produces native apps as output.
Cordova accomplishes this by enhancing the native WebView component on each supported platform. The WebView component is built into each platform and it has access to the underlying system. Cordova establishes a link from the enhanced WebView to the system, via plugins. More on plugins a little later in the course. The result of the Cordova build process is an app with the following architecture, the code you write exists in the web app in the diagram, the rest is taken care of by Cordova when you build for supported platforms.
You'll specify which device capabilities your app will need and add references to the plugins that make those capabilities available. You'll also set some platform-specific preferences in a configuration file to let Cordova know exactly what you want. The result is a native app that has access to the underlying platform OS. I think of Cordova in much the same way I think of the Java programming language, I tell my students all the time that if they want to create desktop applications targeting multiple platforms there aren't very many choices other than using Java, because there is a Java virtual machine available for nearly any desktop platform they can be safe in knowing their application will run almost anywhere.
However, if they are targeting a single platform, Windows, Mac, whatever, then there are probably better choices available that tie directly into the OS. That doesn't mean they can't use Java, it just means that there may be something better. In general, a Java program includes the code that you write in a .java file, which is sent through the Java compiler. The result that comes from the Java compiler is a byte code file with a .class extension.
That .class file is then fed to the Java virtual machine for any given platform where your program will run. The same is true with Cordova relative to the mobile space, if you are targeting multiple platforms, Cordova is an invaluable tool, it allows you to create a single app with a single code base and deploy it to multiple platforms. Java's original value proposition of write once, run anywhere, applies to Cordova in the mobile space. If you are targeting a single platform you might be better served learning that platform's programming language via its SDK and IDE.
In today's world, however, you'll want your app to be available for Android and iOS at the very least. Cordova provides a maintainable solution to provide that and more. So who should use Cordova? I see two possibilities where Cordova can be a very attractive solution, first, as mentioned previously, if you are a mobile developer who wants to target multiple platforms, Cordova can be difficult to overlook. You only need to know how to create web apps instead of mastering Java, Objective-C or Swift, C#, Android Studio, Visual Studio, Xcode and more.
Second, if you are a web developer who wants to convert your existing web app into a native app, again, Cordova is hard to overlook. You can use your existing code to target any of the platforms supported by Cordova. Using Cordova gives you the ability to offer your app in the platform app store, where users want to get their apps, and you get to avoid learning all those complicated platform-specific tools and technologies.
- Understanding Cordova's value proposition
- Installing the Cordova CLI
- Accessing mobile device capabilities, including geolocation and data storage
- Using Android Studio and Xcode in conjunction with Cordova
- Creating platform-specific stylings to match native interfaces