John
John

Reputation: 63

Android NDK: Autogenerate function declarations?

I am trying to use a pre-existing native C library in my android project.. The library builds just fine with the NDK tools...

Now what I've come to understand is that I cannot just call into the library, but my library needs to include jni.h and add specific function declarations, like for example:

JNIEXPORT jint JNICALL Java_com_MultPkg_Mult_mult(JNIEnv *, jobject, jint, jint);

But since I'm using an existing library I that is also used on other platforms I don't like the idea of littering the whole code with these definitions that will only end up wrapping my real functions...

Is there a way around this? And if this really is the only way, is there any way to automatically generate these based on my existing C function declarations/definitions?

Much appreciated

Upvotes: 2

Views: 794

Answers (2)

pdiddy
pdiddy

Reputation: 6297

Use SWIG to auto generate the jni compatible c file. It also generate the .java class so that your android interacts with the java class in which has all the native methods.

Take a look at this : SWIG Android

Upvotes: 0

Gregory Pakosz
Gregory Pakosz

Reputation: 70234

Use the javah tool that comes with your JDK as it's not part of the Android's SDK nor NDK.

Upvotes: 1

Related Questions