const char * LOG_TGA = "LOG_TGA";
添加头文件
#include <android/log.h>
代码:
第三个参数为压迫输出的信息
__android_log_print(ANDROID_LOG_ERROR, LOG_TGA, "hello native log");
对第一个参数进行替换:
ANDROID_LOG_VERBOSE
ANDROID_LOG_DEBUG
ANDROID_LOG_INFO
ANDROID_LOG_WARN
ANDROID_LOG_ERROR
demo:
#include <jni.h>
#include <string>
#include <android/log.h>
const char * LOG_TGA = "LOG_TGA";
std::string hello = "aaa";
void check();
extern "C" JNIEXPORT jstring JNICALL
Java_com_sheng_testcheck_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
check();
return env->NewStringUTF(hello.c_str());
}
void check() {
__android_log_print(ANDROID_LOG_ERROR, LOG_TGA, "------\n");
hello = "Hello from C++";
}