Include .c file instead .cpp

Hello,

I am totally new on using Nsight and NDK and may be someone can give me an insight which I am confuse with. I am playing around the “Android Hello World Demo” project template and everything work fine until I need to add some class in HelloJni.c file. Then I change HelloJni.c to HelloJni.cpp add my new class in the file to make everything compile. However, when I run the app, the app get suck/crash when it called stringFromJNI(). By saying crash I mean I didn’t see anything on the device screen but the VS debugger still running. I guess the code cannot find the actual function since I changed the file name to Hellojni.cpp. How can I fix that? Thanks!

hi Nachochip,
in C++ code call C function. You need extern “C” { you C code} .
for example the HelloWordDemo, you change helloJni.c to HelloJni.cpp. you should change it to like this.

extern "C" {
  jstring 
  java_com_example_hellojni_HelloJni_stringFromJNI(JNIEnv *env, jobject thiz)
  {
     return env->NewStringUTF("Hello Word");
  }
}

That’s exactly what I want. Thanks!