itt 2014 - niklas therning - truly native java apps on ios with robovm
Post on 15-Apr-2017
148 Views
Preview:
TRANSCRIPT
BackgroundMobile app developers face a big problem
Language API Tools Platform
Building apps for multiple platforms is expensive!
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
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!!!
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
– Bjarne Stroustrup
“There are only two kinds of languages: the ones
people complain about and the ones nobody uses”
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
FeaturesRuntime 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
FeaturesSupports Java Native Interface (JNI)
Linked statically
java.lang.Object.class.o
java.lang.String.class.o
java.lang.Class.class.o
Main.class.o libmyjni.a
Linker MyApp
FeaturesJava 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
Limitations• No runtime bytecode loading
• No dynamic JNI (use static)
• No debugging (yet)
• ~Java6 APIs (Java7 syntax)
• Mac required for iOS apps
Current statusUseable
50+ apps in App Store
RoboVM+libGDX — Java game development framework libgdx.badlogicgames.com
Future• Documentation
• Debugging
• Complete Cocoa Touch Bindings
• Toolchain for Windows/Linux
• Java8 APIs using OpenJDK
• Java8 lambdas
• Interface Builder integration
top related