The android ----- JNI log Print

1. Import log file header

In .c / .cpp files that you use in

Import log.h header file

#include<android/log.h>


2. In the Android.mk

Plus

LOCAL_LDLIBS :=-llog

noteAndroid.mkThere is a line include $ (CLEAR_VARS)

Must LOCAL_LDLIBS: = - llog on the back of it to be useful,

Otherwise, I did not write the equivalent.


3. Define LOG function

Define a global variable, and then define LOG function of some output:

#define TAG "myDemo-jni" // This is a custom logo LOG 
 #define LOGD (...) __android_log_print (ANDROID_LOG_DEBUG, TAG, __ VA_ARGS__) // define the type LOGD 
 #define LOGI (...) __android_log_print (ANDROID_LOG_INFO, TAG, __ VA_ARGS__) // define the type LOGI 
 #define LOGW (...) __android_log_print (ANDROID_LOG_WARN, TAG, __ VA_ARGS__) // define the type LOGW 
 #define LOGE (...) __android_log_print (ANDROID_LOG_ERROR, TAG, __ VA_ARGS__) // define the type LOGE 
 #define LOGF (...) __android_log_print (ANDROID_LOG_FATAL, TAG, __ VA_ARGS__) // define the type LOGF 

Function code defined above

Correspond to Java code in Android

Log.d (), Log.i (), Log.w (), Log.e (), Log.f () method and the like.


Example 4

#include <jni.h>
#include <string.h>
#include <android/log.h>

 #define TAG "myhello-jni-test" // This is a custom logo LOG
 #define LOGD (...) __android_log_print (ANDROID_LOG_DEBUG, TAG, __ VA_ARGS__) // define the type LOGD

 extern "C" {
     JNIEXPORT jstring JNICALL Java_com_snail_helloworld_MainActivity_myhello(JNIEnv * env, jobject obj);
 };

 JNIEXPORT jstring JNICALL Java_com_snail_helloworld_MainActivity_myhello(JNIEnv * env, jobject obj)
 {
	 int i = 0;
	 LOGD("########## i = %d", i);
	 return env->NewStringUTF("Hello From CPP");
 }


Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := hello
LOCAL_SRC_FILES := hello.cpp
LOCAL_LDLIBS :=-llog

include $(BUILD_SHARED_LIBRARY)









Intelligent Recommendation

JNi --- Print LOG

Add header file Code: Replace the first parameter:...

JNI (3) Log Print

1. Import the log header file Add a logger.h file, import log.h header file in the file 2. Cmakelists Add Library 3. Define the log function Method 1: Control by variable switch Method 2: Control by c...

android-how to print log to logcat in C/C++ layer in jni

I’m doing android jni development recently, and I need to output some logs to facilitate debugging and analyzing problems, but the jni layer cannot be as direct as pure android development.Log.v...

Use log in android jni

Development environment: ubuntu 10.10 + eclipse + adt +android ndk +  android sdk   1. Create a new simple project: JNIDemo, Design jni to java class:     2, in the android to bin ...

Android JNI log usage

1 add ndk to log support If you need to add ndk support for the log, you only need to do the following 2 steps. 1.1 Modify Android.mk If the generated library file is ".so file", add the fol...

More Recommendation

Android JNI Log

Android JNI Log is a simple wrapper that uses a variable to control whether the Log is output. Note that variable parameter passing is involved here, so to use __android_log_vprint, you cannot use __a...

Android JNI learning - LOG log

Just preparing for a project with JNI development, I thought about using Demo to start with it. After all, I haven't done it for a long time. When I found out that I forgot how to print the Log inform...

JNI-C / C ++ configure Log to print log

In the JNI development process, C / C ++ functions sometimes need to print some information, especially when debugging; This article mainly explains the Log configuration in C / C ++; 1. Add C / ...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top