Reference to:http://www.linuxidc.com/linux/2014-02/96341.htm
Android development, Java can easily use debugging information log.i, LOG.D ..., the JNI layer can use it? The answer is yes.
1 for ease of use, first macro definition:
Eben_hpc_log.h content is as follows:
#ifndef _included_hpc_log
#define _included_hpc_log
#ifdef __cplusplus
extern "C" {
#endif
#include <android/log.h>
Macros define similar Java layer definitions, different levels of log logi, LOGD, LOGW, LOGE, Logf. Yes, log.i log.d in Java.
#define LOG_TAG "HPC-Jnilog"//This is the identity of the custom LOG
#undef Log//Cancel the default log
#define Logi (...) __android_log_print (Android_log_info,log_tag, __va_args__)
#define LOGD (...) __android_log_print (Android_log_debug,log_tag, __va_args__)
#define LOGW (...) __android_log_print (Android_log_warn,log_tag, __va_args__)
#define LOGE (...) __android_log_print (Android_log_error,log_tag, __va_args__)
#define LOGF (...) __android_log_print (Android_log_fatal,log_tag, __va_args__)
#ifdef __cplusplus
}
#endif
#endif
2 Code in use:
Demo.c
#include <jni.h>
#include "Eben_hpc_log.h"
Jniexport jint jnicall java_cn_hpc_cai_jni_jnilogdemo_test (jnienv* env,jobject jobj)
{
LOGD ("Log.d This is Log:java_cn_hpc_cai_jni_jnilogdemo_test () in JNI");
Logi ("Log.i This is Log:java_cn_hpc_cai_jni_jnilogdemo_test () in JNI");
return 0;
}
3 in App/build.gradle
Defaultconfig { NDK { ldlibs "log" modulename "Xal" //generated so name abifilters "Armeabi" // The output specifies the so library under three ABI architectures. Currently dispensable. //abifilters "Armeabi", "armeabi-v7a", "x86" //outputs specify so libraries under three ABI architectures. Currently dispensable. } }
The next step is the Java layer invocation:
4 Java Calls
public static final String libname = "Xal";
static {
System.loadlibrary (libname);
}
{
Jnilogdemo demo = new Jnilogdemo ();
Demo.test ();
}
Complete.
[Android Pro] Call log output debug information in Android Studio JNI