Comparing PhoneGap/Cordova and Codename One
Shai Almog, CEO and co-founder of Codename One, spends some time comparing PhoneGap/Cordova, and Codename One. Check out the advantages that Codename might have in store for you.
Join the DZone community and get the full member experience.Join For Free
First, let's start with a big disclaimer: I'm the co-founder of Codename One so calling me biased would be an understatement. Having said that I would not have bothered comparing Codename One to PhoneGap/Cordova had I not thought that they are excellent tools!
Last time around we compared Codename One to Xamarin and this time around I’d like to compare Codename One to what is probably the market leader: PhoneGap/Cordova. If Xamarin is big then Cordova is huge, it is so prevalent that it is often the default assumption when people mention cross platform today.
In fact, one of the big problems we had when describing Codename One was distinguishing it from HTML5 based solutions like Cordova.
One of the things we’d like to clarify before delving into the comparison is that our goal isn’t to proclaim Codename One as the "end all" of WORA.
We are biased so the comparison might be flawed. However, we think Cordova/PhoneGap are remarkably innovative tools that changed the marketplace significantly. The goal of this comparison is to highlight the differences/tradeoffs of each solution. In fact, we rather like Cordova and even offer some Cordova compatibility in Codename One.
We might do a proper discussion of Ionic as I think it’s a very interesting solution that is very similar to Codename One in some regards. Most of the things we discuss about PhoneGap/Cordova apply to ionic too.
PhoneGap was started in the iPhoneDevCamp hackathon, this highlights the genius behind the solution: the underlying idea is trivial. PhoneGap is, in effect, a very simple solution which is a pretty good thing.
It also includes a rich set of plugins that provide quite a few capabilities, in fact, we just ported one of those great plugins to add Bluetooth support to Codename One.
Adobe purchased Nitobi who made PhoneGap and open sourced the project thru Apache as the Cordova project. Both PhoneGap and Cordova are very similar with PhoneGap offering some pretty interesting features on top of the core open source product such as PhoneGap build.
Because Cordova/PhoneGap is so simple it was adopted throughout the industry practically all major enterprise mobility tools such as Worklight rely on it for their client side UI. It’s become a synonym for the idea of packaging HTML as an application and even tools that are not using Cordova internally are often referred to as PhoneGap or Cordova.
In fact, we even announced PhoneGap/Cordova support a while back and it didn’t take much to implement that.
At a Glance
Packaged code optionally obfuscated
Yes thru PhoneGap build
Depends on framework
This is not feasible in Codename One where the source code is compiled together and obfuscated by default on Android making it even more "secure". A Codename One application can be decompiled but this would be a far harder process than doing the same for a PhoneGap/Cordova application.
This brings about some interesting situations, Android completely replaced it’s browser implementation between versions of the OS relatively abruptly. This can trigger a situation where shipping applications will start misbehaving due to OS changes. This also means that the only way to fix some issues is thru a workaround, there is no central authority that can fix an HTML rendering issue or add a missing feature to an old OS.
With Codename One the VM and UI are the responsibility of a single entity. Since the implementation of Codename One is at a lower point in the porting stack most of the relevant code can be ported/fixed or worked around by Codename One itself. This means that if a low-level reproducible failure happens, Codename One has the ability to fix it whereas PhoneGap developers would need to workaround it.
PhoneGap Build supports building native applications via the cloud which is a wonderful approach. Codename One works in the same way but unlike PhoneGap build, Codename One is built around that approach as a basic expectation.
PhoneGap build works with a set of pre-determined plugins whereas Codename One is more flexible with its support for native code and 3rd party libraries.
Codename One uses lightweight widgets to do it’s rendering. Arguably HTML can be considered lightweight as well but it is often not the case.
Frameworks like Ionic have taken up the lightweight approach to creating native "themes" in a similar way to Codename One. This provides Ionic with many of the advantages Codename One enjoys but also some of the drawbacks/advantages inherent from layering on top of Cordova.
One of the core capabilities of Codename One is in embedding native widgets directly into the app. This is demonstrated in Codename One thru the native Google Maps support and other such capabilities. Since embedding an OS native widget into HTML is "problematic" that level of platform extension can’t be accomplished in Cordova.
Cordova and Codename One can be used to create very small applications. In fact, Cordova can be even smaller than Codename One in the hands of a skilled developer.
Property Cross Comparison
The PropertyCross demo was built as a tool that allows us to compare two cross platform frameworks, as such, there are versions of the demo for many such platforms. You can check out details of the Codename One implementation here. The github repository for this demo is here.
With so many variations how can we properly compare the two frameworks?
There are several things we can glean from property cross by reviewing all of the above:
- Codename One doesn’t have splash screens or multiple icon sizes. Those are generated automatically unlike the PhoneGap-based solutions where you need dozens of resource files even without tablet support!
Notice that Codename One can embed PhoneGap/Cordova code into Codename One applications. Would that make it superior to just using Cordova directly?
However, if you want to use proper Java to develop your app and care more about the security of your code then Codename One has advantages.
Published at DZone with permission of Shai Almog, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.