I have just donwloaded Apache Cordova and it seems like there are platform specific versions. Do I have to code for a specific platform before porting it to another? Is it possible to create a multiplatform project? Am I understand correctly the way I should start working?
This is also what the Apache Cordova homepage says.
And because these JavaScript APIs are consistent across multiple device platforms and built on web standards, the app should be portable to other device platforms with minimal to no changes.
Thanks.
I think that there is a slight gap in your understanding of Cordova. Cordova is used to build hybrid mobile applications. Hybrid means that your application is basically a standard web site built with HTML/CSS/JavaScript, but it has access to native device functionality. Usually when you are building a regular website with JavaScript, you cannot do certain things without working directly in the native code, like taking a picture or going through the Contacts on the phone. However, Cordova allows you to access these native functions just from the JavaScript! And you never have to touch the native code! So you will build one application in HTML/JavaScript/CSS (one uniform codebase!), and after you go through the build process, will have multiple application files, one for each native platform that you "built" it for.
Yes, one major benefit of using Cordova is that you can easily create multiplatform apps. What you do is first create your application in HTML/JavaScript - when you need to use a native API, you can just call the appropriate Cordova JavaScript API - this API is common across all of the platforms, meaning that calling say cordova.someAPI.doCoolDeviceOnlyThingThatBrowsersCantDoYet(parameter)
will expect the same parameters no matter what device the user is using. Your built Cordova app will then call the equivalent native functionality, no matter which OS the app was built for.
In order to create an app for, say, iOS and Android, you will need to set up the appropriate build tools for both platforms. Then what you will do is import your HTML/Javascript files that make up your application into these tools and "build" the native app, which will wrap your HTML/JavaScript in native code, add the device specific Cordova code (usually in the form of something like cordova.jar on Android) and create the downloadable package that you can then publish to app stores. This process of "compiling" your app to the multiple platforms can be a pain, but thankfully there is an automated service that can help, so check out PhoneGap build while it's still free.
You should be able to get started building apps with just your favorite HTML editor, the Ripple emulator, and the Cordova API reference guides. However, you will probably want a real device to test in and build your app with, so you probably will have to set up at least one native environment (like Eclipse with the Android ADT and the appropriate cordova.js file.) (The cordova.js file is very similar between platforms, except for when there are differences between platforms, like in the bridge that handles communication between JavaScript and the native code.)
Hopefully I have answered all of your questions - good luck!
As long as you don't need the API, you can code everything in your browser. However, when you want to test the Cordova API features, you must run on a platform.
The platform specific files (e.g. the eclipse project for android) contain a www folder (assets/www for android) where you have to put all of your code. Within that folder, everything should be cross-platform, with one exception: the cordova.js file that contains the bridge to the native code for each platform.
You can also try Ripple to run a project directly on your browser, which has the advantage of better debugging tools. It is far from being feature comple though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With