Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot locate symbol "__android_log_write" - Android native logging

I am trying to log some info from my native code into logcat but I can't seem to get it working. I have searched all over stackoverflow (and other websites).

In my native code I have #include <android/log.h>. It fully compiles with no errors. If I don't use the logging at all my native code runs in android.

my Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := mylib-prebuilt
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/mylib.so
LOCAL_EXPORT_C_INCLUDES += $(LOCAL_PATH)/$(TARGET_ARCH_ABI)
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := gmp-prebuilt
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libgmp.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(BUILD_SHARED_LIBRARY)

The error I get:

java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "__android_log_write" referenced by <package>

Lastly, the log I use looks like this:

__android_log_write(ANDROID_LOG_ERROR, "Native tag", "Native text");

Does anybody know what is going wrong?

like image 631
Max Avatar asked May 03 '26 14:05

Max


1 Answers

Try -llog in your link step. You need the logging library.

like image 101
Martin Ellison Avatar answered May 06 '26 04:05

Martin Ellison



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!