First off, I'm not a Java guy, by any stretch of the imagination. I had an intro class back in college, probably 8 or 9 years ago. I'm way more comfortable with C/C++/C#. I'm trying to figure out the Android NDK so we can port over some existing code (static libraries written in C) to run on mobile devices. Currently, I'm just trying to get Hello World working and get a feel for the development environment.
From ndkhello.c:
From HelloWorldActivity:
I get an UnsatisfiedLinkError out of the call to fromNative = hello(); I'm suspicious that I miss-named my function in ndkhello.c. Can anyone verify this? Help me to understand the naming convention? Any help is appreciated.
From ndkhello.c:
Code:
#include <string.h>
#include <jni.h>
jstring Java_helloWorld_namespace_HelloWorld_HelloWorldActivity_hello(JNIEnv
* env, jobject this)
{
return (*env)->NewStringUTF(env, "Hello from native code!");
}
From HelloWorldActivity:
Code:
package helloWorld.namespace;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloWorldActivity extends Activity {
// load the library - name matches jni/Android.mk
static {
System.loadLibrary("HelloWorld");
}
// declare the native code function - must match ndkhello.c
private native String hello();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
String fromNative;
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
fromNative = hello();
tv.setText(fromNative);
setContentView(tv);
}
}
I get an UnsatisfiedLinkError out of the call to fromNative = hello(); I'm suspicious that I miss-named my function in ndkhello.c. Can anyone verify this? Help me to understand the naming convention? Any help is appreciated.