ndk中打印log

编译报错: undefined reference to `__android_log_print',于是按照这篇博客的指引,加入了ldLibs "log", "z", "m"

 defaultConfig {
        applicationId "com.yuzhiyun.listenforuninstall"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        ndk{
            moduleName "UninstallKit"
            ldLibs "log", "z", "m"
        }
    }

 就编译通过了,事实上,那篇博客也很好的介绍了在ndk中打印log的步骤.

在c文件中加入:
 
 
[cpp] view plain copy
 
在CODE上查看代码片 派生到我的代码片
  1. #ifndef LOG_TAG  
  2. #define LOG_TAG "ANDROID_LAB"  
  3. #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
  4. #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)  
  5. #endif  

在头文件中加入:

 

[cpp]  view plain  copy
 
  在CODE上查看代码片 派生到我的代码片
  1. #include <android/log.h>  


最为关键的是在APP配置文件中加入以下代码:

 

 

[cpp]  view plain  copy
 
  在CODE上查看代码片 派生到我的代码片
  1. ldLibs "log""z""m"  


这段代码放在

 

android {
ndk {
    //添加代码这里
   }
}

 打印log举例:

LOGD("crate process success,current child pid = %d", pid);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值