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

j2Objc

 j2Objc

Java to iOS Objective-C translation tool and runtime.

Kristijan Rebernisak

January 14, 2017
Tweet

More Decks by Kristijan Rebernisak

Other Decks in Technology

Transcript

  1. • Multiple platforms - shared logic • Server, Web, Android,

    iOS, FW • Developer productivity • Better code quality (single codebase) • Collective code ownership • Concurrent platform releases Why?
  2. • c++ (Dropbox Djinni, Emscripten (An LLVM-to-JavaScript Compiler) + asm.js)

    • React Native (native iOS & Android, UI abstraction, ReactJS, Node.js) • Apache Cordova (ex. PhoneGap, hybrid approach, web UI) • Kotlin (100% interoperable with Java, Android support, compiles to JS) • Xamarin (Microsoft, C#, platform abstractions) • j2objc • GWT How?
  3. • Part of the strategy to share code across platforms

    • Key goal: support concurrent platform releases • Only support client-side development. • Only support business logic code, and stay far, far away from user interface APIs • It’s a transpiler and runtime for iOS apps • Translates Java to Obj-C during build • iOS Foundation Framework focus • Open Source, used by Google Inbox, Sheets, Drive… What is J2Objc?
  4. • In-house Java stack • Performance • Supported by Google

    • Open Source • Tom Ball Why J2Objc?
  5. • Not a cross-platform application tool • No cross-platform UI

    support • Not a Java emulator • Compiled to object files, linked into app • Not for one-time source translation • Comments removed, output reformatted What J2Objc is not?
  6. • Full Java 7 syntax, Java 8 in progress (Apache

    Harmony - Android) • Exceptions try/catch/finally • Inner and anonymous classes, enums, annotations • Static variables • Generic types, threads, synchronization, reflection • Resource loading • JSNI-style native code embedding • Plug & play: Guava, JUnit, Hamcrest, Mockito, JSR305, Protobuf What’s supported?
  7. • lambdas (via Retrolambda) • AutoValue • JodaTime • GSON

    (with JodaTime serialiser) Bellabeat Core+
  8. • To translate: • Run j2objc on command-line or in

    Xcode • Options similar to javac • $ j2objc -classpath <…> -sourcepath <…> -d output-dir HelloTest.java • To compile translated source: • Run j2objcc on command-line • Unknown options forwarded to clang • $ j2objcc -o hellotest -l junit output-dir/HelloTest.m How is it used?
  9. • Java packages become camel-cased prefix • java.util.List -> JavaUtilList

    • java.util.Map.Entry -> JavaUtilMap_Entry • File names map directly • java/util/ArrayList.java -> java/util/ ArrayList.m, .h Class Name Mangling
  10. • Translator generates ARC or reference counting code (default) •

    cycle_finder tool reports memory cycles • @Weak, @WeakOuter annotations break cycles • WeakReference just works Memory options
  11. • Contributors from Android, iOS, Backend and Data team •

    3 months running in production with no issues • Improved code quality for core business logic • Data algorithms, firmware API, domain models + de/serialization Impact
  12. • Complex setup • Small development team • Bugs •

    Documentation • iOS team may hate you Issues
  13. • Bug fixes and performance improvements • Java 8 •

    Dagger 2 DI • Dead code elimination with ProGuard Future plans