码迷,mamicode.com
首页 > 其他好文 > 详细

NDK之打印调试信息Log

时间:2016-11-24 15:14:26      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:androi   mil   detail   const   for   and   default   write   x86   

第一步:gradle配置ndk

  ndk {
            moduleName "Iso8583Lib"
            ldLibs "log", "z", "m"
            abiFilters "armeabi", "armeabi-v7a", "x86" //输出指定三种abi体系结构下的so库,目前可有可无。
        }

第二步:在需要的C文件加载头

#include <android/log.h>

第三步:定义打印方便使用的函数

#define LOG_TAG  "C_TAG"
#define LOGD(...)  __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)

第四步:测试使用

#include <jni.h>
#include <com_example_lanhe_android_jnistringdemo_jni_HelloWorld.h>
#include <android/log.h>
#define LOG_TAG  "C_TAG"
#define LOGD(...)  __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)

JNIEXPORT jstring JNICALL Java_com_example_lanhe_1android_jnistringdemo_jni_HelloWorld_getHelloWorld
  (JNIEnv *env, jobject thiz){
  jstring hello = (*env)->NewStringUTF(env, "Hello Jni");
  int helloLen=(*env) -> GetStringLength(env,hello);
  LOGD("hello.length=%d",helloLen);
  return hello;
}

结果如下:

 技术分享

 

额外:使用 __android_log_write 也是可以的。

技术分享

 

备注: 

调用其中的日志打印:

int __android_log_write(int prio, const char *tag, const char *text);

第一个参数为打印级别,为以下枚举之一:

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;

 参考资料:

http://blog.csdn.net/h183288132/article/details/50379450

 

NDK之打印调试信息Log

标签:androi   mil   detail   const   for   and   default   write   x86   

原文地址:http://www.cnblogs.com/H-BolinBlog/p/5869184.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!