Search code examples
javaandroidc++java-native-interfacejniwrapper

Calling native functions from Android Java - alternative to JNI


This might be a really rookie question, but I'm writing an Android app that needs to use a .so library written in C++. The .so is made up of several classes, and is in generic C++, not JNI.

Is there a way to call the C++ functions from the Android Java app, other than JNI? Everything I've seen about JNI suggests that you have to rewrite the native code to be JNI-specific, and that is really damn inconvenient if you're only given a .so.

What alternative methods exist for calling native functions from a java application in Android 4.0.3? How simple would it be to write a small JNI-C++ program that calls the C++ functions, and can then be called from Java?

Is there anything in Eclipse that will simplify the process?

I probably shouldn't be surprised that there isn't a more elegant solution.


Solution

  • I do not believe there is a more elegant solution than the one you suggested of writing a JNI wrapper for the library. It is probably not a good idea anyway as you should be compiling separate versions of all your native code for each architecture you want to support. Just attaching to a compiled library means you are hamstrung by it's architecture.