Skip to content

SwiftAndroid/swift-jni

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

swift-jni

The start of a JNI wrapper for swift-android (later for other platforms too, presumably)

It uses a Swift-like API wherever possible. i.e., GetIntArrayRegion returns [Int], and other JNI methods may take Int as a param instead of jsize etc. Oftentimes however it wouldn't make sense to take or return anything but the raw JNI pointer (e.g. NewIntArray, NewGlobalRef etc.)

The naming has been kept as close to the C-functions as possible, including omiting parameter names, and documenting differences where not immediately obvious. That way the vast majority of documentation is done for us via the JNI docs.

Usage

Internally the module uses JNI_OnLoad (which could be problematic if the user wants to use their own) to initialise an implicitly unwrapped global, jni.

This global can be then used from Swift code (from any thread) to run standard JNI functions like jni.GetIntArrayRegion(jarray), to return an array of Swift Ints

See the article here for why (and a bit of how) this project came to be: https://medium.com/@ephemer/using-jni-in-swift-to-put-an-app-into-the-android-play-store-732e542a99dd#.rtviqfdlu

About

Wrap JNI functions (WIP)

Resources

License

Stars

Watchers

Forks

Packages

No packages published