编译报错: 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文件中加入:
- #ifndef LOG_TAG
- #define LOG_TAG "ANDROID_LAB"
- #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
- #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
- #endif
在头文件中加入:
- #include <android/log.h>
最为关键的是在APP配置文件中加入以下代码:
- ldLibs "log", "z", "m"
这段代码放在
android {
ndk {
//添加代码这里
}
}
打印log举例:
LOGD("crate process success,current child pid = %d", pid);