DeepMedia logo
Open Source

Search...

Other versions of this page

Improve this page on GitHub

Search

Concepts

Motivation

Native and JVM binaries have historically communicated through the Java Native Interface, which is a bridge across two different environments and runtimes. This imposes strict restrictions about what kind of data can be passed through the interface and how, together with the need to write very tedious boilerplate communication code on both platforms.

Additionally, when using Kotlin/Native, the developer is required to deal with verbose, low-level kotlinx.cinterop types in order to pass and receive JNI data. But Kotlin also creates an opportunity to improve communication by using the same language on the two ends of the bridge.

Our aim with Knee is to leverage this fact and, with the power of Kotlin compiler plugins, provide a transparent, seamless interface between the two environments so that all the conversion boilerplate - whenever is needed - is hidden from the developer.

Design

⚠️

Note: Support is currently limited to Android Native targets, where jni.h is imported by default. Adding other platforms should be straightforward though, and we welcome contributions on this.

In source code and documentation, you may see the following terms representing the two ends of the bridge:

  • backend refers to the Kotlin/Native side (code, environment, binaries)
  • frontend refers to the Kotlin/JVM side (code, environment, binaries)

Knee is designed around the use case where the vast majority of the logic lives in the backend module, and the frontend is just a very thin wrapper around it. This way, developers can just write once in the backend.

This is done via a compiler plugin and a companion runtime library, that together:

  • Analyze backend code, transforming it where needed and generating glue code and JNI boilerplate code
  • Generate frontend source code as .kt files, including all the declarations that are supposed to pass through the bridge
  • Provide runtime utilities to deal with JNI functions in general (e.g. currentJavaVirtualMachine)

On this page

More

Subscribe to the DeepMedia Newsletter

The latest news about DeepMedia products, open source projects and software development at our company.

By clicking “Subscribe”, you agree that DeepMedia may use your email address to send you newsletters, including commercial communications, and to process your personal data for this purpose. You agree that DeepMedia may process said data using third-party services for this purpose in accordance with the DeepMedia Privacy Policy. You can revoke this consent at any time using the unsubscribe link included in each email or by writing at contact@deepmedia.io.