Using JNI to invoke C + + under Android is quite normal in developing the game. But debugging the C + + section is a very troublesome issue. If you quickly locate the crash location. The NDK provides a gadget ndk-stack.
First, we configure the environment to configure the NDK path and the ADB path to the environment variables. As below:
Adbpath = F:\DevelopTools\adt-bundle-windows-x86_64-20131030\sdk\platform-tools
Ndkroot = F:\DevelopTools\android-ndk-r9d
Path =%path%;%ndkroot%;%adbpath%;
Next, go to our root directory of the project and execute the following command:
ADB Logcat | Ndk-stack-sym Obj/local/armeabi
Start the debug game with the following error
Crash Dump: **********Build Fingerprint:'Generic/sdk/generic:2.3.3/gri34/101070:eng/test-keys'PID:571, Tid:571>>> Com.example.hellojni <<<Signal One(SIGSEGV), code1(Segv_maperr), fault addr00000000Stack Frame I/DEBUG ( -): #xxPC 00000eb0/data/data/Com.exampringfromjni at C:\Users\zhangchuanwei\workspace1\hellojni/jni/hellojni.cpp: AStack Frame I/DEBUG ( -): # onPC 00017d74/system/lib/Libdvm.sstack Frame I/DEBUG ( -): # GenevaPC 00048f08/system/lib/Libdvm.sstack Frame I/DEBUG ( -): #GenevaPC 00041ab6/system/lib/Libdvm.sstack Frame I/DEBUG ( -): #GenevaPC 0002976c/system/lib/Libdvm.sstack Frame I/DEBUG ( -): # toPc00021020/system/lib/Libdvm.sstack Frame I/DEBUG ( -): # .PC 0005f5de/system/lib/Libdvm.sstack Frame I/DEBUG ( -): # -PC 00066fce/system/lib/Libdvm.sstack Frame I/DEBUG ( -): # ,PC 0001cfd4/system/lib/Libdvm.sstack Frame I/DEBUG ( -): # thePC 000220dc/system/lib/Libdvm.sstack Frame I/DEBUG ( -): #TenPC 00020fd0/system/lib/Libdvm.sstack Frame I/DEBUG ( -): # OnePC 0005f430/system/lib/Libdvm.sstack Frame I/DEBUG ( -): # APC 0004b9a8/system/lib/Libdvm.sstack Frame I/DEBUG ( -): # -PC 0003ebb0/system/lib/Libdvm.sstack Frame I/DEBUG ( -): # -PC 000314ac/system/lib/Libandrostack Frame I/DEBUG ( -): # thePC 000322c6/system/lib/Libandrostack Frame I/DEBUG ( -): # -PC 00008ca2/system/bin/App_procstack Frame I/DEBUG ( -): # -PC 00014db8/system/lib/libc.so
Directly can see the 22nd line of our project there are errors, look at the next 22 lines is what
- struct strtest{ Char* pstr; - }; strtest *ptest=NULL; ptest->pstr=NULL; at return Env->newstringutf ("Hello World returned". ");
For ndk-stack use, you can look at the docs/ndk-stack.html file under the NDK root directory
Source: Http://files.cnblogs.com/chuanwei-zhang/hellojni-dynamic.zip
Static Const Char* ClassName ="com/example/hellojni/mainactivity"; Jniexport jstring jnicall stringfromjni (jnienv*env, Jclass clazz) { //return Env->newstringutf (env, "Hello form jni!"); structstrtest{Char*pstr; }; Strtest*ptest=NULL; Ptest->pstr=NULL; returnEnv->newstringutf ("Hello World returned.");}
Download the source code, and replace the hellojni.cpp inside the above function, you can reproduce the above problem.
Ndk-stack debugging Android C + + code crash location