Skip to content

How are bindings to existing native frameworks generated?

florianf edited this page Nov 18, 2017 · 8 revisions

RoboPods

If you're looking for a binding to a popular 3rd party library, it maybe already be done by the RoboPod project. For a list of current supported libraries take a look at: https://github.com/MobiVM/robovm-robopods/issues/1

bro-gen

bro-gen is a Ruby script that generates RoboVM bindings semi-automatically. You need to write a YAML mapping file for the library to generate the binding. For details head over to our fork of bro-gen which works with the current RoboVM version https://github.com/MobiVM/robovm-bro-gen

For some examples of YAML mapping files take a look at the config files for the iOS Cocoatouch or UIKit bindings in this repository https://github.com/MobiVM/robovm/tree/master/compiler/cocoatouch/src/main/bro-gen Those mappings are automatically generated with our bro-gen fork.

Admob tutorial

Generate Admob Bindings with bro gen Tutorial

Create bindings manually

For small to medium sized libraries it maybe feasible to write the bindings manually. For a simple example binding take a look at the bindings to the SVGgh library https://github.com/florianf/robopod-ghs-svg.

The original RoboVM documentation has a nice introduction to the binding mechanism used by RoboVm https://github.com/MobiVM/robovm/wiki/The-Bro-Java-to-Native-Bridge

Tips & Tricks

  • CGRect and CGSize method parameters should always be annotated with the @ByVal annotation.
  • Bro doesn't support float, always use a double annotated with @MachineSizedFloat

Simple example

@Method(selector = "asImageWithSize:andScale:")
public native UIImage asImageWithSize(@ByVal CGSize maximumSize, @MachineSizedFloat double scale);