Headers with Android NDK
android, android-ndk
Solution
Your LOCAL_C_INCLUDES should include the `../../../src/` or `../../../inc` directory in order for you to use `#include <mylib/utils/Timer.hpp>` i.e:
LOCAL_C_INCLUDES := ../../../src/
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 :
LOCAL_LDLIBS = -lz -lm
LOCAL_LDLIBS := -llog
If you want to append to a make directive use:
LOCAL_LDLIBS := -lz -lm
LOCAL_LDLIBS += -llog
or `LOCAL_LDLIBS := -lz -lm -llog`
EDIT: Using the following Android.mk it seems to work if you run ndk-build from the Android/jni directory.
LOCAL_PATH := $(call my-dir)
# first lib, which will be built statically
#
include $(CLEAR_VARS)
LOCAL_MODULE := MyLib
LOCAL_C_INCLUDES := ../../../inc/
LOCAL_SRC_FILES := ../../../src/mylib/utils/Timer.cpp
include $(BUILD_STATIC_LIBRARY)
# second lib, which will depend on and include the first one
#
include $(CLEAR_VARS)
LOCAL_MODULE := MyNativeFinalSharedLib
LOCAL_LDLIBS := -lz -lm -llog
LOCAL_CPPFLAGS := -std=c++0x
LOCAL_STATIC_LIBRARIES := MyLib
include $(BUILD_SHARED_LIBRARY)
Also you forgot to put LOCAL_PATH := (call my-dir) on the first line and some other missing make directives.
An Android.mk file must begin with the definition of the LOCAL_PATH variable. It is used to locate source files in the development tree. In this example, the macro function 'my-dir', provided by the build system, is used to return the path of the current directory (i.e. the directory containing the Android.mk file itself).
(from android-ndk-r8d/docs/ANDROID-MK.html)
Problem
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.