Android(安卓)ndk开发之在c文件里打印log
There are three step in total
step one:
add "LOCAL_LDLIBS := -llog " to your android.mk file
like:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := hellolog
LOCAL_SRC_FILES := native.c
include $(BUILD_SHARED_LIBRARY)
step two:
include <android/log.h> as header in you c file, and define LOG_TAG、LOGE(...)like:
#include <android/log.h>
#define LOG_TAG "plus.c"
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
you can also define a yourlog.h file, define all kinds of log, then include this into your c file, like:
=====mylog.h=======
#include <jni.h>
#include <android/log.h>
#define LOG_TAG "hgllog.h"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)
step three:
use yourself define LOGE() print info as you want, like:
LOGE("this is log info string....");
LOGE("this is log info string.... and str is %s", str);更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer