Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ITT 2014 - Niklas Therning - Truly Native Java Apps on iOS with RoboVM

ITT 2014 - Niklas Therning - Truly Native Java Apps on iOS with RoboVM

Niklas introduces and runs demos of RoboVM - a new open-source project with the goal of bringing Java and other JVM languages to iOS devices. The RoboVM ahead-of-time compiler translates Java bytecode into native code that runs directly on the CPU without the overhead of an interpreter. Access to the iOS Cocoa Touch APIs is provided through a Java to Objective-C bridge enabling the development of apps with truly native UIs and full hardware access.

Istanbul Tech Talks

May 14, 2014
Tweet

More Decks by Istanbul Tech Talks

Other Decks in Programming

Transcript

  1. Background Mobile app developers face a big problem Language API

    Tools Platform Building apps for multiple platforms is expensive!
  2. Background C heritage • NULL dereference from disaster: int *values

    = NULL; ... *values = 10; // Crash! • No array bounds checking int array[10]; ... array[100] = 10; // Danger! Problems with Objective-C
  3. Background Extremely dynamic • Objects exchange messages: Java: obj.method(arg); ObjC:

    [obj method:arg]; Problems with Objective-C Number number = Double.valueOf(3.14); for (int i = 0; i< 100000000; i++) { number.doubleValue(); } NSNumber *num = [NSNumber numberWithDouble:3.14]; for (int i = 0; i < 100000000; i++) { [num doubleValue]; } Time: 0.54 s Time: 2.05 s 3.8 x slower!!!
  4. Background No managed memory • malloc() / free() • CFRetain()

    / CFRelease() • ARC is great but doesn’t prevent cycles Problems with Objective-C C A B retainCount=1 retainCount=1 retainCount=1
  5. – Bjarne Stroustrup “There are only two kinds of languages:

    the ones people complain about and the ones nobody uses”
  6. The RoboVM project • Goal: Java on iOS • +

    other JVM languages: Scala, Clojure, … • Started in 2010 - open-sourced in Jan 2013 • github.com/robovm • License allows closed source apps • www.robovm.com / @robovm
  7. Requirements • A Mac • Mac OS X 10.9+ •

    Xcode 5.x • Oracle’s Java 7 JRE
  8. Features Runtime classes based on Android java.lang.Object.class java.lang.String.class java.lang.Class.class RoboVM

    compiler java.lang.Object.class.o java.lang.String.class.o java.lang.Class.class.o
  9. Features Java to native bridge — Bro Call native code

    without JNI @Library("c") public class Abs { static { Bro.bind(); } @Bridge static native int abs(int i); public static void main(String[] args) { System.out.println(abs(-100)); } } Supports structs, enums, callbacks
  10. Limitations • No runtime bytecode loading • No dynamic JNI

    (use static) • No debugging (yet) • ~Java6 APIs (Java7 syntax) • Mac required for iOS apps
  11. Current status Useable 50+ apps in App Store RoboVM+libGDX —

    Java game development framework libgdx.badlogicgames.com
  12. Future • Documentation • Debugging • Complete Cocoa Touch Bindings

    • Toolchain for Windows/Linux • Java8 APIs using OpenJDK • Java8 lambdas • Interface Builder integration