What is wrong with my make file?
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := foo
LOCAL_SRC_FILES := foo.c
LOCAL_EXPORT_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
foo.c
#include <string.h>
#include <jni.h>
#include <android/log.h>
#define LOG_TAG "foo"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
void test() {
LOGI("test");
}
ndk-build
foo.c:9: undefined reference to `__android_log_print'
Try the following in your
Android.mk
file:Add
to Android.mk
You need to add
to Android.mk
This helped for me:
Android.mk
If you use Android Studio and gradle, it ignores Android.mk. Add this to your build.gradle file:
Yes, you do need to add:
LOCAL_LDLIBS := -llog
as the other answers/comments have specified, however the original question did not specify if he use the jni library as:LOCAL_JNI_SHARED_LIBRARIES
or asLOCAL_REQUIRED_MODULES
.I can pretty much say for sure that he has it used it as:
LOCAL_REQUIRED_MODULES
because of theLOCAL_EXPORT_LDLIBS := -llog
in the question... unless that was added after an edit.If you use
LOCAL_REQUIRED_MODULES
the shared library is installed in /system/lib instead of into the apk, because it is a required module. Therefore you will need to addLOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
instead of justLOCAL_LDLIBS := -llog
so that when the build system is building & linking the jni shared library, it will have the-llog
definitions in the correct place, available to be built under$OUT/root/system/lib
. Otherwise you will continue to get the same answer, even if you only addLOCAL_LDLIBS := -llog
.So, those who commented that the
-L
is not needed, and the other answer was correct, they were actually incorrect in this situation.