Fork me on GitHub
Warning! RoboVM is pre-alpha software. It's not yet ready for production use. Expect to be bitten by bugs. If you find a bug, please report it.

To be written...

Installation instructions

RoboVM compiler dependencies

The RoboVM compiler requires the following tools to be installed on your system:

  • Java JDK 6 or newer - Oracle's JDK or OpenJDK
  • LLVM 3.2
  • An assembler - GCC (on Linux) and clang (on Mac OS X) are used as assembler frontends
  • A linker - GCC (on Linux) and clang (on Mac OS X) are used as linker frontends
  • Mac OS X only: To run iOS apps in the simulator or on a device you will need Xcode 4.6.2 installed

Mac OS X

Download and install Java SE JDK 7 from Oracle.

Install Xcode 4.6.2 from the Mac App Store. It includes clang and and the iOS simulator.

Download and install the LLVM tools to /opt/llvm by running the following commands in a terminal:

curl -O http://llvm.org/releases/3.2/clang+llvm-3.2-x86_64-apple-darwin11.tar.gz
sudo mkdir -p /opt
sudo tar xvfz clang+llvm-3.2-x86_64-apple-darwin11.tar.gz -C /opt
sudo rm -f /opt/llvm
sudo ln -s /opt/clang+llvm-3.2-x86_64-apple-darwin11 /opt/llvm

Ubuntu 12.04 (AMD64)

Most of the required tools are available in the standard Ubuntu repositories. In a terminal:

sudo apt-get install build-essential g++-multilib openjdk-7-jdk

Download and install the LLVM tools to /opt/llvm:

curl -O http://llvm.org/releases/3.2/clang+llvm-3.2-x86_64-linux-ubuntu-12.04.tar.gz
sudo tar xvfz clang+llvm-3.2-x86_64-linux-ubuntu-12.04.tar.gz -C /opt
sudo rm -f /opt/llvm
sudo ln -s /opt/clang+llvm-3.2-x86_64-linux-ubuntu-12.04 /opt/llvm

On Linux we need to download an ICU data file and place it in /usr/share/icu:

sudo mkdir -p /usr/share/icu
sudo sh -c 'curl "http://download.robovm.org/icudt48l.dat" > /usr/share/icu/icudt48l.dat'

Installing RoboVM

Download the latest RoboVM release or use a package built by following the build instructions then run the following commands in a terminal to install it to /opt/robovm:

sudo tar xvfz robovm-0.0.2.tar.gz -C /opt
sudo rm -f /opt/robovm
sudo ln -s /opt/robovm-0.0.2 /opt/robovm

If you had a previous RoboVM version installed it is recommended that you remove the cache of compiled classes:

rm -rf ~/.robovm/cache

Your first RoboVM program

Now let's compile a simple Java program into a native executable using RoboVM. First create HelloWorld.java in a new folder with the following contents:

public class HelloWorld {
    public static void main(String[] args) {
         System.out.println("Hello world!");
     }
}

Compile HelloWorld.java using javac:

mkdir classes
javac -d classes/ HelloWorld.java

Finally, compile the Java bytecode into native code using:

/opt/robovm/bin/robovm -verbose -cp classes/ HelloWorld
Note! When you compile a program using RoboVM it will translate not only the main class into native code but also the transitive dependencies of that main class. So the first time you compile a program for a particular CPU and OS RoboVM also compiles many of the standard runtime classes such as java.lang.Object, java.lang.String, etc. A simple class like HelloWorld references about 1500 classes directly or indirectly. RoboVM keeps a cache of compiled classes and only recompiles a class when it or any of its direct dependencies have changed.

You should now have a native executable called HelloWorld/HelloWorld. Since we didn't specify a CPU or OS to the /opt/robovm/bin/robovm command the compiler will produce a binary which can be run on the current system (either Linux or Mac OS X). Running it should print:

Hello world!

Let's take a quick peek at the contents of the HelloWorld folder:

HelloWorld/lib/boot/robovm-rt.jar
HelloWorld/lib/classes0.jar
HelloWorld/HelloWorld

This is the final product for this simple console program. The jar files in HelloWorld/lib/boot/ are the jar files which were specified using the -bootclasspath command line argument. Since we didn't specify anything RoboVM will add robovm-rt.jar for us. The jar files directly in HelloWorld/lib are the jar files specified using -cp argument. If one specifies a path (like we did) rather than a jar file RoboVM will archive the contents of that path in a jar file and call it classes0.jar (subsequent paths will be archived to classes1.jar, classes2.jar, etc). The jar files will be stripped from .class files. The reason why the jar files are included by stripped is to make it possible to store property files, images, etc in the classpath rather than in the file system.

A simple iOS app

While it's nice to be able to make native console programs like we did above the main goal of RoboVM is to make it possible to develop iOS apps in Java. Let's make a very simple iOS app. Put the following into IOSDemo.java:

import org.robovm.cocoatouch.coregraphics.*;
import org.robovm.cocoatouch.foundation.*;
import org.robovm.cocoatouch.uikit.*;

public class IOSDemo extends UIApplicationDelegate.Adapter {

    private UIWindow window = null;
    private int clickCount = 0;

    @Override
    public boolean didFinishLaunching(UIApplication application,
            NSDictionary launchOptions) {
  
        final UIButton button = UIButton.fromType(UIButtonType.RoundedRect);
        button.setFrame(new CGRect(115.0f, 121.0f, 91.0f, 37.0f));
        button.setTitle("Click me!", UIControlState.Normal);

        button.addOnTouchUpInsideListener(new UIControl.OnTouchUpInsideListener() {
            @Override
            public void onTouchUpInside(UIControl control, UIEvent event) {
                button.setTitle("Click #" + (++clickCount), UIControlState.Normal);
            }
        });

        window = new UIWindow(UIScreen.getMainScreen().getBounds());
        window.setBackgroundColor(UIColor.lightGrayColor());
        window.addSubview(button);
        window.makeKeyAndVisible();
        
        return true;
    }

    public static void main(String[] args) {
        NSAutoreleasePool pool = new NSAutoreleasePool();
        UIApplication.main(args, null, IOSDemo.class);
        pool.drain();
    }
}

Compile IOSDemo.java using javac:

mkdir classes
javac -cp /opt/robovm/lib/robovm-rt.jar:/opt/robovm/lib/robovm-objc.jar:/opt/robovm/lib/robovm-cocoatouch.jar -d classes/ IOSDemo.java

Compile the Java bytecode into native code and launch the app using:

/opt/robovm/bin/robovm -verbose -arch x86 -os ios -cp /opt/robovm/lib/robovm-objc.jar:/opt/robovm/lib/robovm-cocoatouch.jar:classes/ -run IOSDemo

Using the Eclipse plug-in

Now lets install the RoboVM Eclipse plug-in and try it out. Open Eclipse, go to Help → Install New Software, and paste the URL below into the dialog box. Select the RoboVM for Eclipse feature and click Next and follow the instructions.

http://download.robovm.org/eclipse/

After the plug-in has been installed and Eclipse has been restarted we can create a new RoboVM iOS project by selecting File → New → Project.... Select the RoboVM → RoboVM Cocoa Touch Project project type. Give the new project a name and leave all other settings at their defaults.

Create a new class (File → New → Class) and call it IOSDemo with no package name. Copy the IOSDemo.java code from the section above and paste it into the editor replacing whatever Eclipse auto generated for you.

Finally, launch the app in the iOS simulator by right clicking the project you created and select Run As... → iOS Simulator App.

Please see the GitHub project wiki for build instructions.