Android JNI配置CMakeLists.txt修改.cpp在logcat打印日志
C/C++代码里面常用的printf没法在Android 的logcat输出显示。需要特别配置C++才能显示在logcat里面。
(1)CMakeLists.txt定义:
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
target_link_libraries( # Specifies the target library.
application #自己的库
# Links the target library to the log library
# included in the NDK.
${log-lib} )
(2).cpp中:
#include <string>
#include <android/log.h>
const char *TAG="fly";
#define LOG __android_log_print
void LOGI(const char *info, const char *c) {
std::string str = info;
LOG(ANDROID_LOG_INFO, TAG, str.append("%s").c_str(), c);
}
void LOGI(const char *info, int num) {
LOGI(info, std::to_string(num).c_str());
}
void LOGI(const char *info) {
LOG(ANDROID_LOG_INFO, TAG, "%s", info);
}