2010.10.21 How to use "logcat" in JNI

The four instructions for using “logcat” in JNI:

   1. Include the header file “android/log.h” as follows:

           #include <android/log.h>

   2. Define the need functions as follows:

       I only the one.

           #define LOGD(…) __android_log_print(ANDROID_LOG_DEBUG  , “liblog”,__VA_ARGS__) 

      Other functions is below:

           #define LOGV(…) __android_log_print(ANDROID_LOG_VERBOSE, “liblog”,__VA_ARGS__)

           #define LOGI(…) __android_log_print(ANDROID_LOG_INFO, “liblog”,__VA_ARGS__)

           #define LOGW(…) __android_log_print(ANDROID_LOG_WARN, “liblog”,__VA_ARGS__)

           #define LOGE(…) __android_log_print(ANDROID_LOG_ERROR, “liblog”,__VA_ARGS__)

   3. You can use the LOGD function in the source code.

          LOGD(“Debug Message is from JNI”);

   4. Add some words in the file “Android.mk” 

          LOCAL_LDLIBS :=  -L$(SYSROOT)/usr/lib -llog

      P.S. I refer some information that tell me add the line under “LOCAL_PATH := $(call my-dir)”. When I build the JNI code, the undefined reference always happened. So I move the line above the line “include $(BUILD_SHARED_LIBRARY)”, then the error disappeared. I think that the reason is the path of the directory.

Leave a Reply

Your email address will not be published. Required fields are marked *