XMLVM.org Main Page Overview Documentation Stories Download Contribute Contact Check out our tutorials

Overview: Android to iPhone


Android is an Open Source platform for mobile devices. Initiated by Google, Android has received much attention. Android applications are developed using Java, although a special compiler converts class files to a proprietary, register-based virtual machine that is used on Android devices to execute applications. Android defines its own API for writing mobile applications. With the help of XMLVM it is possible to cross-compile Java-based Android applications to native iPhone applications. The diagram depicts the relationship between the Android and iPhone version of the application.

The Android application is written in Java and makes use of an Android specific API. XMLVM offers a compatibility library, written in Java, that offers the same API as Android, but only makes use of the Java-based API for Cocoa Touch. During the cross-compilation process, both the application and the Android compatibility library are cross-compiled from Java to Objective-C and linked with the Cocoa Touch compatibility library to yield a native iPhone application.

The code below shows an excerpt from the Android Compatibility Library. The Android class android.widget.Button is a wrapper for the Cocoa class UIButton. When a click handler is added to an android.widget.Button instance, method setOnClickListener() adds an instance of the Cocoa class UIControlDelegate to the UIButton via the corresponding method addTarget(). The code below will be cross-compiled to Objective-C:

package android.widget;

public class Button extends View {
   protected UIButton button;

   // ...

   public void setOnClickListener(OnClickListener listener) {
        final OnClickListener theListener = listener;
        button.addTarget(new UIControlDelegate() {

            public void raiseEvent() {

        }, UIControl.UIControlEventTouchUpInside);

XMLVM includes a demo that demonstrates the power of cross-compiling Android applications to the iPhone. The demo is an Android version of the classic Sokoban game called Xokoban. An online version (requires Java) of Xokoban can be played in XMLVM's own iPhone emulator.

SourceForge.net Logo