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

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,如下
 1 #include <stdarg.h>
2
3 #ifdef __cplusplus
4 extern "C" {
5 #endif
6
7 /*
8 * Android log priority values, in ascending priority order.
9 */
10 typedef enum android_LogPriority {
11 ANDROID_LOG_UNKNOWN = 0,
12 ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */
13 ANDROID_LOG_VERBOSE,
14 ANDROID_LOG_DEBUG,
15 ANDROID_LOG_INFO,
16 ANDROID_LOG_WARN,
17 ANDROID_LOG_ERROR,
18 ANDROID_LOG_FATAL,
19 ANDROID_LOG_SILENT, /* only for SetMinPriority(); must be last */
20 } android_LogPriority;
21
22 /*
23 * Send a simple string to the log.
24 */
25 int __android_log_write(int prio, const char *tag, const char *text);
26
27 /*
28 * Send a formatted string to the log, used like printf(fmt,...)
29 */
30 int __android_log_print(int prio, const char *tag, const char *fmt, ...)
31 #if defined(__GNUC__)
32 __attribute__ ((format(printf, 3, 4)))
33 #endif
34 ;
35
36 /*
37 * A variant of __android_log_print() that takes a va_list to list
38 * additional parameters.
39 */
40 int __android_log_vprint(int prio, const char *tag,
41 const char *fmt, va_list ap);
42
43 /*
44 * Log an assertion failure and SIGTRAP the process to have a chance
45 * to inspect it, if a debugger is attached. This uses the FATAL priority.
46 */
47 void __android_log_assert(const char *cond, const char *tag,
48 const char *fmt, ...)
49 #if defined(__GNUC__)
50 __attribute__ ((noreturn))
51 __attribute__ ((format(printf, 3, 4)))
52 #endif
53 ;
54
55 #ifdef __cplusplus
56 }
57 #endif
58
59 #endif /* _ANDROID_LOG_H */


 
  





你可能感兴趣的:(android)