Java on iOS has been a sore spot for Java developers, with Apple restricting deployment on its iOS smartphones and tablets, though Java developers have forged workarounds that let them build apps for the devices just the same. One of these technologies, RoboVM, was featured at the recent JavaOne technical conference in San Francisco.
RoboVM translates Java bytecode into native ARM or x86 code and includes a Java-to-Objective-C code bridge. It has mostly been used in gaming apps so far, but project founder Niklas Therning expects to branch out to other types of apps when the 1.0 version debuts in November or December. He responded to questions via email about RoboVM recently from InfoWorld Editor at Large Paul Krill
InfoWorld: What exactly are the limitations on running Java on iOS?
Therning: Apple has allowed embedded interpreters in apps since late 2010, as long as those apps also embed all scripts needed by the app. Even if [a previous restriction was still in effect], it wouldn't have been a problem for RoboVM since it doesn't launch other executables and doesn't embed an interpreter or interpret any code at runtime. With RoboVM, all bytecode is Ahead-Of-Time-compiled into machine code at compile time on the developer machine, and the final app is more similar to apps built with Xcode and Objective-C/Swift than a traditional Java application …. As we've already proved with RoboVM, Java and other JVM languages on iOS is totally doable while still complying with Apple's iOS developer program license agreement. I don't really see any problems with Apple's guidelines.
InfoWorld: What is revolutionary, if anything, about RoboVM's approach?
Therning: RoboVM is the only solution that makes it possible to use the new Java 8 language features, such as lambdas and default methods. RoboVM is unique in that it provides full access to the hardware and the native iOS APIs through a set of Java-to-Objective-C bindings. Using these bindings, you can do everything you could have done if you used Apple's Xcode and Objective-C/Swift to build your app.
InfoWorld: Does RoboVM's approach involve JavaFX?
Therning: RoboVM makes it possible develop cross-platform apps using the JavaFX GUI framework and reuse up to 100 percent of the code between platforms. We are currently working with LodgOn to make JavaFX for mobile devices, both iOS and Android, work great. RoboVM is in no way dependent on JavaFX, though. If you're more interested in developing apps using native UI components, you can do that instead. In our talk at JavaOne 2014, we showed how one can build an app for both Android and iOS using native UIs but still reuse large portions of the code between the two platforms.
InfoWorld: How does RoboVM differ from approaches like Codename One, in which "Java bytecode is translated to native C/Objective-C code and compiled using Xcode for seamless mobile application development," according to that company's site?
Therning: In RoboVM, we've taken a slightly different approach in our Ahead-Of-Time compiler. Instead of targeting C/Objective-C as done in Codename One, we take advantage of the LLVM project's tool chain. You could view RoboVM as a front end for LLVM, which consumes Java bytecode and translates it into LLVM bitcode, which is then optimized and translated into machine code by the LLVM back end. LLVM supports a whole range of different CPU architecture and OSes; in theory, it should be possible to make RoboVM target all of them.
But right now, the focus is on iOS. By targeting LLVM bitcode rather than C/Objective-C, as done by Codename One, we have more control over the final machine code, and we can produce tighter and faster code than would have been possible with C/Objective-C.