I am using __android_log_print and cannot print log messages on logcat

This is a .cpp file, and the code

JNIEXPORT jint JNICALL Java_com_example_compute_MainActivity_AddNumbers(JNIEnv *env, jobject obj, jint v1, jint v2)
{
_android_log_print(ANDROID_LOG_VERBOSE, "VaxVoIP", "The value of 1 + 1 is %d", 1+1);

         return -1;

    //return (v1 + v2);
}

This is the Android.mk file

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

Here we give our module name and source file.

LOCAL_MODULE    := add
LOCAL_LDLIBS := -llog
LOCAL_SRC_FILES := add.cpp\
                   add.h\

include $(BUILD_SHARED_LIBRARY)

And another error I'm trying to solve is to make a .so file

_android_log_print(ANDROID_LOG_VERBOSE, "VaxVoIP", "The value of 1 + 1 is %d", 1+1);
was not declared in this scope
+3
source share
4 answers

John is right. I just decided to turn it on by including #include <android/log.h>and also adding LOCAL_LDLIBS + = -llog -ldl -landroid to the android.mk file

+1
source

If this is the entire .cpp file, you will need to # include something that _android_log_print defines.

0
source

Do not forget to enable

#include <android/log.h>
0
source

Probably due to the buffer. Put \nat the end of the line.

__android_log_print(ANDROID_LOG_VERBOSE, "VaxVoIP", "The value of 1 + 1 is %d\n", 1+1);

Also remember to add double underscores, not just one underscore.

0
source

All Articles