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
This helped for me:
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := nativeDemo
LOCAL_SRC_FILES := main.cpp
LOCAL_LDLIBS += -llog
include $(BUILD_SHARED_LIBRARY)
In the android studio version 2.2 and higher, there is inbuilt support for CPP when you create a new project. Also, the liblog.so is included by default. Nothing to be done apart from including the header file (android/log.h).
Checkout app/CMakeLists.txt that is created by the studio when we create new android studio project. We can see that the find_library() block and target_link_libraries() block for loglib are already present.
Also, pay attention towards the function syntax. It should be:
__android_log_print (int priority, const char *tag, const char *fmt,...);
In my case, I had left out tag parameter and ended up spending good 3 days in figuring it out.
More about CMake: Add C and C++ Code to Your Project
In case the project you are working on has the following characteristics that differ from other 'standard' answers:
The following target_link_libraries usage makes it:
find_library(ANDROID_LOG_LIB log)
target_link_libraries(${TARGET_NAME} ${ANDROID_LOG_LIB})
Being TARGET_NAME
the name of the target to build (having set it up before with add_library
or add_executable
).
find_library
is equally important as well as setting up the toolchain properly (use the toolchain provided by Android SDK at ANDROID_SDK_HOME/cmake/<version>/android.toolchain.cmake
so it sets up CMAKE_SYSROOT
which is used by find_
commands).