您的位置:首页 > 移动开发 > Android开发

Android ndk开发之在c文件里打印log

2014-03-09 16:27 453 查看

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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  log Android ndk