Android development ndk related issues

index:
NDK Compile and use static library, dynamic library
jni header file generation Method to use Android Log
in NDK's Nactive code
Analyze NDK crash stack information
ndk-gdb debugging method

NDK compile and use static library, dynamic library
Too complicated, see New article: http://android development NDK Compile and use static library, dynamic library

jni header file generation:
1. Declare Java Native interface. (The Java Native interface can be defined in the main class of the Android project, or by using a separate class.)
static { System.loadLibrary("libxxx"); }
public native void init()
2. Compile the java code.
javah -classpath $(BIN_PATH) com.xyzclassname
3. Then you can see the com_x_y_z_classname.h header file in the current path, and it is ok to implement it.
Note: $(BIN_PATH) refers to the location of the bin after class compilation. For android development, it is generally under $project/bin/.
 
How to use Android Log in NDK's Nactive code
1. Add in mk file:
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
2. Add in 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, you can download this python script from http://code.google.com/p/android-ndk-stacktrace-analyzer/, and then use adb logcat -d > logfile to export Crash log, use arm-eabi-objdump located under build/prebuilt/linux-x86/arm-eabi-4.2.1/bin to convert so or exe into assembly code, such as: arm-eabi-objdump -S mylib.so > mylib.asm, use the script python parse_stack.py <asm-file> <logcat-file>
2 Use arm-eabi-addr2line under NDK directly (recommended)
For example: arm-eabi-addr2line -C -f -e libxxx. so 0x##### (0x##### is the top pc value in the address output log, which can be traced back to the final function call sequence)


ndk-gdb debugging method
1 AndroidManifest.xml <application> contains android: debuggable = "true"
2 Execute ndk-build NDK_DEBUG=1
3 Add a breakpoint before the java code calls c, then add b ***.c:main
   breakpoint to the gdb command line and add the method android.os.Debug.waitForDebugger();
4 Execute ndk-gdb
  ndk-gdb --start --force --verbose displays more information to see what went wrong in the step.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326780576&siteId=291194637