Skip to content Skip to sidebar Skip to footer

Android Ndk Native Function Call Issue

I am attempting to write an Android application that makes use of the GNU Scientific Library (GSL). In particular, I am interested in 'libgslcblas.so' for its BLAS implementation.

Solution 1:

Read up on JNI. In short, arbitrary global C functions are NOT callable from Java via NDK. In order to be callable, a function needs a very specific signature, along the lines of:

voidJava_com_mypackage_MyClass_MyMethod(JNIEnv *jni, jobject thiz, jint arg1);

On the Java side, that would be a method of class MyClass in package com.mypackage:

nativevoidMyMethod(int arg1);

Obviosly, vanilla sqrt won't fit the bill. So you need to provide a Java-friendly wrapper for every function you intend to call from Java. With that in mind, you'll probably want to provide wrappers for higher-level concepts that mere math primitives. The Java/C border is messy; the less you cross it, the better.

Also, the library needs to be built from sources specifically for Android. NDK has the tools for that. A ready-made binary for another platform (say, Linux or Windows) won't be usable.

EDIT: The javah tool from JDK can take a Java class with a bunch of native declarations and make skeleton H/C files with dummy implementations. Essentially, translate the method prototypes from Java to C along the JNI rules.

Solution 2:

make sure the library you are trying to use (and its dependencies) are built for target platform (Android Native platform).

Post a Comment for "Android Ndk Native Function Call Issue"