tags:

views:

33

answers:

1

Hi, I am new in ndk development in android.I have gone through the file system of ndk android. Here, explaining what i have done. 1) i have created a folder named "jni" then create 2 file named Android.mk and ndkfoo.c.

In Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

# Here we give our module name and source file(s)
LOCAL_MODULE    := ndkfoo
LOCAL_SRC_FILES := ndkfoo.c

include $(BUILD_SHARED_LIBRARY)

and in ndkfoo.c

#include <string.h>
#include <jni.h>

jstring Java_com_mindtherobot_samples_ndkfoo_NdkFooActivity_invokeNativeFunction(JNIEnv* env, jobject javaThis) {
 return (*env)->NewStringUTF(env, "Hello from native code!");
}

then i have created NdkFooActivity class, in which i have written

// load the library - name matches jni/Android.mk
 static {
  System.loadLibrary("ndkfoo");
 }

But now when i build from cygwin in xp it creates .so file successfully then i run as android application. It gives me java.lang.UnsatisfiedLinkError in LOGCAT.

So, Please let me know where i am wrong.

Thanks in Advance,

+1  A: 

There's a good chance the signature is wrong, as others have mentioned.

If you run the javah utility, you can find the exact signature. From the bin folder in your project, where the .apk is and the root of the Java class hierarchy is generated, run:

javah -o jni_sig.h com.mindtherobot.whatever.your.package.is.NdkFooActivity

...and, if you got the package name and class name correct, it will write out a header (called jni_sig.h) with the correct function signature(s) for any native functions. Copy that to your header and .c file, adding parameters as needed, and it should work correctly.

SomeCallMeTim