Index:
Ndk compiles and uses static and dynamic libraries
JNI header file generation
Use Android log in nactive code of ndk
Analyze the stack information of ndk crash
Ndk-GDB debugging method
Ndk compiles and uses static and dynamic libraries
Too complicated. See the new article: http: // Android ndk for compiling and using static and dynamic libraries.
JNI header file generation:
1. Declare the Java Native Interface. (Defining Java Native interfaces can be declared in the main class of the android project, or by using independent classes .)
Static {system. loadlibrary ("libxxx ");}
Public native void Init ()
2. Compile the Java code.
Javah-classpath $ (bin_path) COM. x. y. Z. classname
3. Then, you can see the header file com_x_y_z_classname.h in the current path and implement it as OK.
Note: $ (bin_path) refers to the position of bin after class compilation. for Android development, it is generally under $ Project/bin.
Use Android log in nactive code of ndk
1. Add the following to the MK file:
Local_ldlibs: =-L $ (sysroot)/usr/lib-llog
2. Add the following to the CPP file:
# Include <Android/log. h>
# Define Logi (...) _ android_log_print (android_log_debug, "keymatch", _ va_args __)
3. Use:
Logi ("Some log here, % s, % d" ,__ file ,__ line __);
Analyze the stack information of ndk crash
1 Google provides a Python script that can be downloaded from the http://code.google.com/p/android-ndk-stacktrace-analyzer/, and then use ADB logcat-D> logfile to export the crash log, use arm-Eabi-objdump to convert so or EXE to assembly code under build/prebuilt/linux-x86/bin, such as arm-Eabi-objdump-s mylib. so> mylib. ASM, use the script Python parse_stack.py <ASM-File> <logcat-File>
2 directly use the arm-eabi-addr2line below ndk(Recommended)
Example: arm-eabi-addr2line-C-f-e libxxx. so 0x ###### (0x #### it is the top PC value in the address output log and can be traced back to the final function call sequence)
Ndk-GDB debugging method
1 androidmanifest. xml <Application> contains Android: debuggable = "true"
2. Run ndk-build ndk_debug = 1.
3. Add a breakpoint before Java code calls C, and then add B ***. C: main to the gdb command line.
Breakpoint addition method Android. OS. Debug. waitfordebugger ();
4. Run ndk-GDB.
Ndk-GDB -- start -- force -- verbose displays more information to view errors in the step.