I am trying to run an easy Android ndk app in c, but I get UnsatisfiedLink Error for the stringFromJNI() function.
Any help would be appreciated. I am quite fluent in C, but my java is a little bit rusty. I have been trying a lot of tips from the web concerning naming, but so far no luck. Here are my files:
hello-jni.c:
#include <string.h>
#include <jni.h>
jstring
Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,
jobject thiz )
{
return (*env)->NewStringUTF(env, "Hello from JNI !");
}
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c
include $(BUILD_SHARED_LIBRARY)
I compile this with ndk-build and all goes well, it provides me with a libnative.so, that is located in the project directory. I use eclipse for the rest.
NdkFooActivity.java :
package com.narola.Testndk;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
public class NdkFooActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ndk_foo);
Log.i("comes at point","hay...");
Log.d("value is : ",""+stringFromJNI());
}
public native String stringFromJNI();
public native String unimplementedStringFromJNI();
static {
System.loadLibrary("hello-jni");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_ndk_foo, menu);
return true;
}
}
Thank you for any suggestions, been searching for a few hours now!
The problem is in the
hello-jni.cfile.You have method signature in c file is
Java_com_example_hellojni_HelloJni_stringFromJNIelse in your activity the package name iscom.narola.Testndk.The method signature has format like
Java_packagename_activityname_methodname(In package name (.)Dot will be replaced by underscore).In your case try like
Java_com_narola_Testndk_NdkFooActivity_stringFromJNI