Codename One : Cross platform native mobile development
I had the chance, during my third year class, to work on an integration project where we got an idea to conceive and develop for three different technologies : JavaFX for desktop, the Symphony PHP framework for the web app, and J2ME as the mobile technology. The challenge in learning J2ME was in its limitations. But it was a good to-get-started step, that initiated us for our fourth year class (specially those who got specialized in mobile systems, like I did, or in embedded systems, like I thought I would do!). Yet, starting this fall, J2ME is no longer taught in my school, the course was replaced by Codename One workshops. And as I cant miss a single opportunity to learn, when friend of mine asked if I can ‘help him with Codename One’ I said ‘No, but we can figure it out together’. We learnt how to perform basic CRUD operations and integrate a third-party API to ‘our’ codename one project, and here I am trying to share what I learnt starting with this article.
What is codename one ?
Codename One was developed by Chen Fishbein and Shai Almog, co-founders of the LWUIT project. It was first announced in 2012 as a cross-device platform for developers to write apps in Java for all device platforms like iPhone/iPad, Android, Windows Phone 7 & 8, Blackberry, Windows Desktop, J2ME devices, Mac OS, and Web. It features a simulator, designer and ports to multiple OS’s. You can learn more about Codename One and its capabilities at their web site.
Codename One vs…
There are other platforms for creating native mobile applications for Android, iOS, BlackBerry and Windows Phone, using the same source code written in Java, c# or other languages: using Cordova/Phonegap you can develop hybrid cross-platform apps for every device. Appcelerator’s Titanium gives you the possibility of creating almost-cross-platform apps, using Javascript that is executed in a Javascript engine. And there is Xamarin that uses C# for cross-platform development (with some native code to be written though).
How does it work ?
You won’t require any native SDKs, your app is gonna be built in the cloud, using a build server. After being built, the application can be downloaded to your desktop, or directly to a mobile phone. Codename One’s build servers handle the work of changing Java code into native code and it produces surprisingly optimised code. With iOS, the translated Java code can perform up to 3x faster than native Objective-C code.
To send your new application to the build server, right-click on the project and select to CodenameOne -> Send {{platform-name}} build. Then login to your CodenameOne account, and the application is sent to the build server for adding the finishing touches, and can be downloaded.
Setting up Codename One
You can install Codename One in any Java IDE you want. These tutorials help you add the Codename One plugin to your IDE whether it’s Netbeans , IntelliJ IDEA or Eclipse. You can not use Codename One with Android Studio though as it uses a different build engine.
You can then start building your cross platform app ! This is a fast glimpse on us creating our first Codename One project ! You have to follow up with these tutorials to actually start !
How to GUI ?
The good news is that Codename One comes with a Designer . It saves the UI in a resource file and can be designed without the source files available. Java is not required to make the GUI, you just drag and drop elements on the screen. The Codename One LIVE application can show a live preview of your design as you make it.
However ! I prefer creating the GUI through code, the reason might be that it takes a few extra time to learn using the GUI builder, or that I really got used to building my guis coding them.
To open the Designer tool, search for theme.res file in your project and double-click it :
This will start the Designer tool where you can customize your theme, use the GUI Builder, fonts and images.
Any demos ?
So that was ‘ Codename One in a nutshell ‘ . But if you need to sink into the real Codename One world then check out on my tutorials, where I provided the code source for the explained demos.
Recent Comments