Thursday, July 22, 2010

True cross-compilation for Android and iPhone?

I went to another presentation on mobile development, this time it was for the xmlvm project presented by Arno Puder. Most of the frameworks that I've seen so far that attempted to ease cross platform development in the mobile space seemed to tackle the problem in similar ways. They introduce some kind of soft layer between your code and the underlying OS and hardware. 

This is where xmlvm sets itself apart from the rest. It does not rely on a runtime or interpreter to abstract the code from the underlying layers. The development cycle looks a bit like this:
  1. Write an android app in Java, with eclipse and the android plugin.
  2. Build your UI and other components using the xmlvm library
  3. Build and execute within their own emulator
  4. Repeat
  5. When you want the real thing, run their compilation tool which compiles native binary code for either Android or iPhone.
I hope I got that right, it's what I remember from the talk. The most interesting and unique part is step number 5. How do they do this? Java and Objective-C are such drastically different languages, this can't possibly be reliable.... right? The trick is that it doesn't work at the language level. The cross compilation uses the java byte code as the source, parses and morphs the logic into an XML document (hence the name) and from that XML, it can generate several types of output applications. This is brilliant.

Wait, did he say "their own emulator"!?
Yes I did. They have their own iPhone emulator so that you can test your code without having to go through the process of cross compiling (yet). From the demo that was shown, it works great. It might even be better than Apple's emulator since there are controls for tweaking the accelerometers. Arno even showed a demo app on his iPod which connected remotely to his emulator running on his laptop. He was then controlling the emulator's accelerometer by moving around his iPod. All of this, of course, is developed using xmlvm.

So far, I'm quite impressed, but there are differences between Android and iPhone that are more complex than just syntax. A question that I had was how the memory model is managed between the two outputs. Java uses Garbage Collection while Objective-C uses the retain/release model and that impacts how you write your code. I didn't grasp exactly the answer that Arno gave me, but in essence he said they use reference counting and so circular references would cause memory leaks. This part would need to be understood clearly by any developer that would adopt this technology to make sure they really understand how their memory is being managed on the device that they are targeting. 

Xmlvm most likely violates the Apple's terms of service and they are aware of this. However, I consider it to be in the same gray zone as Titanium and PhoneGap. An important distinction is that xmlvm generates a true native binary and is probably much harder for the Apple app review process to prove that an app was actually built using a cross-compiler than the other frameworks that rely on interpreters.

The presenter made it clear that this library is not perfect and still has a way to go, but if this technology really does as much as what was presented, then I am definitely interested. I'll have to fiddle with it when I have a chance, now that I have my brand new and free nexus one. Oops! Did I just say that!?

1 comment:

  1. That's a smart approach to cross compiling. I really like how extensible it is; if they ever wanted to add Windows Phone 7 support, it's just a new emulator and an XML>C# converter away, and that's true for any other platform as well.

    Also, Congrats on the Nexus One! That's pretty awesome.

    ReplyDelete