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

调试android通过jni调用的C++代码

2012-02-24 16:57 615 查看
1、头文件
#include <android/log.h>
2、宏定义
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, "mytest", __VA_ARGS__)
3、代码中打印
LOGD("test test test");
int i = 12;
LOGD("%d",i);
4、注意打印字符串可以用下面两个函数
__android_log_print

__android_log_write

但是打印整数等,就必须用下面这个函数了

__android_log_print

原因参见文件/system/core/include/android/log.h,如下
#include <stdarg.h>

#ifdef __cplusplus
extern "C" {
#endif

/*
* Android log priority values, in ascending priority order.
*/
typedef enum android_LogPriority {
ANDROID_LOG_UNKNOWN = 0,
ANDROID_LOG_DEFAULT,    /* only for SetMinPriority() */
ANDROID_LOG_VERBOSE,
ANDROID_LOG_DEBUG,
ANDROID_LOG_INFO,
ANDROID_LOG_WARN,
ANDROID_LOG_ERROR,
ANDROID_LOG_FATAL,
ANDROID_LOG_SILENT,     /* only for SetMinPriority(); must be last */
} android_LogPriority;

/*
* Send a simple string to the log.
*/
int __android_log_write(int prio, const char *tag, const char *text);

/*
* Send a formatted string to the log, used like printf(fmt,...)
*/
int __android_log_print(int prio, const char *tag,  const char *fmt, ...)
#if defined(__GNUC__)
__attribute__ ((format(printf, 3, 4)))
#endif
;

/*
* A variant of __android_log_print() that takes a va_list to list
* additional parameters.
*/
int __android_log_vprint(int prio, const char *tag,
const char *fmt, va_list ap);

/*
* Log an assertion failure and SIGTRAP the process to have a chance
* to inspect it, if a debugger is attached. This uses the FATAL priority.
*/
void __android_log_assert(const char *cond, const char *tag,
const char *fmt, ...)
#if defined(__GNUC__)
__attribute__ ((noreturn))
__attribute__ ((format(printf, 3, 4)))
#endif
;

#ifdef __cplusplus
}
#endif

#endif /* _ANDROID_LOG_H */


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐