I’m trying to compilate my own library with the Android NDK But I’ve got some problems.
Here is my Android.mk file:
# Define vars for library that will be build statically.
include $(CLEAR_VARS)
LOCAL_MODULE := MyLib
LOCAL_SRC_FILES := ../../../src/mylib/utils/Timer.cpp
LOCAL_C_INCLUDES := ../../../src/mylib/
# Optional compiler flags.
LOCAL_LDLIBS = -lz -lm
LOCAL_LDLIBS := -llog
LOCAL_CPPFLAGS := -std=c++0x
include $(BUILD_SHARED_LIBRARY)
When I build my project with “ndk-build” I’ve got the following error :
Clean: mylib [armeabi]
Clean: stlport_shared [armeabi]
Clean: stlport_static [armeabi]
Compile++ thumb : mylib <= Timer.cpp
jni/../../../src/mylib/utils/Timer.cpp:1:34: fatal error: mylib/utils/Timer.hpp: No such file or directory
compilation terminated.
For information, I’m including the .hpp like that :
#include <mylib/utils/Timer.hpp>
I don’t know why headers aren’t found, my library working in Xcode and eclipse.
Thanks for your time!
Edit: Here is my project’s architecture to understand my problem: https://i.stack.imgur.com/wrcAC.jpg
I’m trying to indicate where is located my “.hpp” files in the Android.mk file.
Your LOCAL_C_INCLUDES should include the
../../../src/or../../../incdirectory in order for you to use#include <mylib/utils/Timer.hpp>i.e:Why don’t you put your C and C++ headers and source files inside the jni/ directory of the Android project, near the Android.mk file?
See: What is the difference between #include <filename> and #include "filename"?
Also this is incorrect, because the second LOCAL_LDLIBS overrides the previous LOCAL_LDLIBS directive in the current module :
If you want to append to a make directive use:
or
LOCAL_LDLIBS := -lz -lm -llogEDIT:
Using the following Android.mk it seems to work if you run ndk-build from the Android/jni directory.
Also you forgot to put LOCAL_PATH := (call my-dir) on the first line and some other missing make directives.
(from android-ndk-r8d/docs/ANDROID-MK.html)