David T. David T. - 1 month ago 8x
C++ Question

How do i call C/C++ code from Android using JNA?

I'm trying to integrate this specific library to my Android project, and the library is written in C/C++. I've miraculously gotten

to give me the needed

However, looking at it, there's a sample in the project, and they use a mysterious
with the API bindings of the

How do i either

  • create this special
    file that has the API, based on the


  • directly add a method to the main
    file and then call it from Java?

I've tried to re-wrap things using JNI, but it definitely doesn't seem to work. i keep getting

A lot of the documentation online uses jni as the tutorial. i'm happy with just a few links to tutorials on JNA.


JNA provides a stub native library, libjnidispatch.so for a variety of platforms. You can build this library yourself, or extract one of the pre-built binaries from the project's lib/native/<platform>.jar packages.

You include libjnidispatch.so in your Android project the way you would any other JNI library. This is required; you cannot rely on JNA to dynamically unpack and use its native library automatically like on other platforms. The JNA project includes details for doing so (as well as instructions for building libjnidispatch.so yourself).

You then use jna.jar as you would any other Java jar file, and write your own (Java) mappings to match the native library you're trying to access. There's also a jna-min.jar which omits all the native platform libraries that are normally bundled in jna.jar.