Tip for mobile developers - A look at Codename One
Codename One (CN1) is a java-based platform allowing mobile application developers to create real native mobile apps across multiple platforms with a single code base. It provides all the necessary tools to build, theme, debug and simulate in java.
Many platforms are supported, in order to allow real cross-platform development: iOS (iPhone & iPad), Android, BlackBerry, Windows Phone 7 (8 and RT to come) and J2ME (for older devices, with some obvious limitations).
It allows the developers to build rich user interfaces through lightweight component and access hardware such as camera, GPS, Etc. The SDK and Tools are open source and can be used for free, but they also provide premium services (Cloud storage, Cloud compilation, Support, Etc.)
The founders, Shai Almog and Chen Fishbein, have worked for Sun Microsystems for a while. Chen was the creator of LWUIT, a widget toolkit for building user interfaces for devices (mobile, TV, Etc.). They decided to create their own project without having to deal with bureaucracy and started from scratch with their mutual experience. Just out of the beta phase, it is now quite stable and quite powerful.
Read on for an in-depth look at the platform and read our interview with Shai Alog.
1. Principle of the technology
CN1 is a cross-platform technology for mobile development targeting multiple targets, each one has a different building process.
Android, J2ME & RIM
The standard Java Code is executed as is. A code translation from Java 5 to JDK1.3 cldc is performed seamlessly in order to run on J2ME/RIM devices.
CN1 uses XMLVM to generate native code (Objective-C / C), and XCode to build the final application.
The current solution is a C# translator, but other solutions are being experimented, so this could change in future versions.
In order to obtain fast performance, CN1 uses the native gaming API of most platforms to draw UI.
Source: Codename One principle
2. Plugin and API
All major standard components are available and customizable, such as Label, Button, CheckBox, RadioButton, Slider, Spinners and many others. In addition, you can find more complex components like Tree, Map, MediaPlayer, WebView or List. Complementing these, several types of Layout components are available to create extremely personalized interfaces. All the components can be customized through properties or can be extended, and you can easily adapt their look and feel for each platform
Source : Component list
CN1 supports four distinct options for storage: FileSystem, Storage, SQL & Cloud.
File System but its only available on Android and allows you to store on the SD card.
In order to store data locally, you should use the Storage class included in CN1. It uses the applications private data storage. In iOS, application data is removed when the application is uninstalled.
CN1 provides a cloud service for premium users. It allows you to store object of type CloudObject or binary files directly in their cloud storage system. Its a convenient solution.
You can also use SQL, most of actual devices contains sqlite, a very lightweight SQL database. CN1 doesnt recommend sqlite to portability because it isnt supported by all devices.
You can refer to table behind to choose the solution corresponding to your needs:
Source: Developer guide
Internationalization for texts and dates is supported (L10n/i18n). The format can be easily defined using the included tools.
CN1 provides a NetworkManager to facilitate WebServices requests via http/https. Coupled with JSON/XML parsing, its an easy solution for backend communication.
As a complement, you have access to a network monitor tool which allows you to debug network connections.
Themes are created directly in CN1. You can create a theme for all platforms or specify a different theme for each one. Some default themes are proposed out of the box, including native themes that reproduce specific OS themes.
Theming in CN1 has many capabilities. Among these, we should mention 9-scaling, as well as the auto-generation of multiple resolution copies of an image. This tool has been designed to allow developers and designers to collaborate easily.
Layout & Animations
Several layouts are proposed to create highly customizable UI : XLayout, YLayout, TableLayout, GridLayout, Etc.
CN1 provides some built-in transitions that can be extended, but you can choose to create your own effects to apply to views or directly to components.
Several solutions are proposed to monetize your application, like Vserv, StartApp, Zooz or Inneractive. Integration is easy, and no code writing is required when using the GUI Builder.
A non-official Maven plugin is available (waiting for version 1.1) and offers:
· automated snapshot repo for CN1 artifact builds
· release artifact repo for CN1 artifacts
· snapshot/release repos for 3rd party libraries compatible with CN1
· a Maven archetype plugin for generating Maven-based CN1 apps using template projects
· a Maven Plug-In for interacting with CN1 build server
· a Maven Plug-In for integrating the CN1 tools such as the Device Simulator, Resource Editor/GUI Builder with a Maven-based environment
· Several built-in parsers are available for JSON, XML and CSV.
· A Log API allows you to trace errors and information. As a premium user you can also send email in order to receive final users crashes.
· CN1 gives developers the ability to get to the native platform. This could be useful for accessing some extra functionality available on only some platforms. The process is quite simple, you just have to implement an interface for your native code.
· Analytics and Facebook integration
· Performance monitor
· Push notifications
CN1 supports iOS, Android 2.3.x and 3.x, Blackberry, Windows Phone simulators.
Netbeans and Eclipse can be used to develop applications. A plug-in is available on both IDE and contains project templates for creating simple project quickly, a GUI Builder to construct UI by drag and drop, everything necessary to create themes and a simulator to run your app locally while emulating the chosen target device.
Since the CN1 server provides native source code, you can use every native tools available on the target platform. (XCode for iOS, etc.)
5. Compilation (Cloud & In-House)
For unlimited cloud compilations you must have a subscription (Users are otherwise limited to 100 builds per month). You can launch builds directly from your IDE by choosing the target platform. Your code is compiled and java byte code is transferred. The build is performed on cloud and the generated application can be downloaded from their website, or installed on a device directly with a QR-Code or an email. Moreover, sources can be downloaded as well.
The building process can be run locally, but requires multiple environments and software depending on target platform.
For example, youll need to install XMLVM who allows you to cross-compile Java to Objective-C/C to create a native iOS application.
Some details can be found here: http://sjhannah.com/blog/?p=227
· No support for in-house building
· Serialization is not supported
· Currently signing J2ME applications isn't supported
Theres currently not a lot of feedback on performance and since the building processes can evolve, performance can as well. The best way is to give it a try or wait for user feedback.
However, even if performances cannot be limited to code execution speed, its an important component, even more so when Java is known for its shortcomings in this field. Steve Hannah made a benchmark to compare C, Java and Obj-C on iOS device. Results are pretty correct and give a good start on performance investigations.
Code execution speed result
Explanation: Codename One can be both Virtual Java and Static Java. It depends on the way you code, knowing that you should focus on virtual Java.
8. Next release (1.1)
The final release of 1.0 is planned for the end of the month of January 2013 and should be out at publication date.
Codename One tries to consult the community through online surveys to know what people want to be available for the future of the technology. Of course, every request cannot be fulfilled.
Heres a non-exhaustive list of what has been asked and is planned to be implemented in the next version (1.1).
- Support for Windows Phone 8: This is the main request from the community
- Library support
- Continuous integration
- Charts API: Decision for its integration in 1.1 is not decided yet
Release pace: Every 4 months
An interview with Shai Almog
Our thanks to Shai Almog for kindly agreeing to this interview.
BC: The CN1 project is a revolution in the Java World. Can you tell us how it started? What have been the key milestones?
Chen started LWUIT 5 or 6 years ago at Sun, I was running a consulting business at the time and Chen gave me a call to ask for advice. I told him he was crazy, its a huge undertaking and even if he is successful on that then getting something out through the Sun bureaucracy was practically impossible. He did make great progress in 6 months after which his manager Yoav Barel brought me in to help.
Over the years we tried to build a grand vision for the product but this clashed with how Sun viewed the product internally versus Java FX mobile (which never materialized). Eventually, we decided that things won't get better with Oracle and the only way to take our vision forward is on our own. So we quit Oracle and started rethinking everything, now that there is no corporation with vested interests behind the project how would we have done things from scratch?
Initially our plans were very complex but over the years as a consultant I learned time and time again the process of simplifying and cutting to the core of product value... So we simplified the product and the message until we had the MVP (minimal viable product) with which we soft launched the initial beta).
BC: Youve announced the release of version 1.0 for January and version 1.1 for May. Which are the mainsprings and driving objectives of these evolutions?
I find that when you set hard deadlines you start cutting down features to make them and end up with a better product by going from milestone to milestone. If you give yourself too much time then you procrastinate and don't get immediate user feedback which is probably the most important thing. This was what made Chrome such a great browser and why Mozilla copied their release fast mentality. This works extremely well for open source projects such as ours, getting stuff out to people fast is crucial and even more so in mobile.
BC: Codename One is a young technology, how do you feel about its reception in the Java community?
I think that while its young its also remarkably familiar to most Java developers, Eclipse/NetBeans, Swing like API, GUI builder etc. Most Java developers find the "hooks" to get started. The main challenges for developers is working with a cloud service from a young and unknown startup. This challenge we can only overcome with time and the examples of the developers that are picking the project.
Since our initial private beta we have had 100k developers download our SDK and build thousands of unique applications that are already deployed on many millions of devices.
BC: In mobile applications, performance is a major concern for users and developers. How can you ensure the best compatibility with all platforms?
By translating everything to native we guarantee native or even better performance (with some caveats), to provide the compatibility our client side library adapts everything to the behavior and convention of every platform. We spent the past 5-6 years dealing with device compatibility & performance issues from well before there was an iPhone. We find that devices on the low layers are very similar, the problems start when you raise the abstractions to the higher level. Unlike other solutions in this area our porting layer is very low level and has several different layers of abstractions and solutions to deal with device differences.
BC: WindowsPhone8 & BlackberryOS10 will be released this year. Do you think this will bring a major challenge to you? Will you support them as soon as possible or wait for indicators of technology adoption?
We already have BB10 support coming out soon, its relatively easy to offer basic support by using the work we did for Android. We didn't want to announce it for 1.0 to avoid the pressure of delivering this but it should be pretty easy.
Windows Phone 8/RT is somewhat challenging. Microsoft broke compatibility with Windows Phone 7.x for Windows Phone 8, on top of that there is Windows RT for the tablets which also requires a separate build from the Windows Phone 8 (its possible we will also need a build for the full Windows 8 on intel). So its possible we will need 4 different builds to support Windows on all the devices. We have several different angles we are working on right now to achieve this but we don't want to announce anything because we had a problematic experience with Windows Phone 7. When doing that port we picked a specific direction, had a proof of concept working then divulged information about the direction we were taking which eventually we had to backtrack and redo everything differently. Some platforms are tough, but after doing the iOS port (which we had to redo several times), we are pretty confident we can reach any platform.
BC: In order to convince those who still hesitate, can you name some companies or projects that have already adopted CN1?
We are still working with big ticket customers some of which I can't name. Vodafone has used Codename One in the past to build at least one application and we have worked with one of the biggest operators in the USA. Other than that we are working with many integrators in building their applications, our product is still in beta as I write this and a great deal of our customers aren't ready to launch without a guarantee of repeatable builds that will be delivered with our 1.0 product.
Sometime after that point I'm confident we will be able to point out some of the partnerships we have in place by name.