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 Xamain 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.
At a Glance
|Category ||PhoneGap/Cordova ||Codename One |
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 it’s 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.
Since PhoneGap/Cordova is mostly an infrastructure tool there are several implementations that support PhoneGap Build. E.g. jquerymobile, ionic, sencha touch and too many others to even count…
With so many variations how can we properly compare the two frameworks?
There are several things we can gleam from property cross by reviewing all of the above:
Codename One doesn’t have splashscreens or multiple icon sizes… Those are generated automatically unlike the PhoneGap based solutions where you need dozens of resource files even without tablet support!
The Codename One implementation has 623 lines of code out of which over 150 lines are comments and 40 lines are import statements…
Who says Java is verbose?
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.
If you think we misrepresented Codename One or PhoneGap/Cordova in any way let us know in the comments.