I have an Android JNI project I’d like to compile with ndk-build. The project contains of multiple third-party sub projects.
+- jni
+- Android.mk
+- my-proj.mk
+- other-proj.mk
+- my-proj
+- a.cpp
+- b.cpp
+- other-proj (third-party)
+- c.cpp
+- d.cpp
The idea now is to include/import the makefiles of all sub projects in Android.mk, like this:
LOCAL_PATH := $(call my-dir)
include $(LOCAL_PATH)/my-proj.mk
include $(LOCAL_PATH)/other-proj.mk
other-proj is built as static library. my-proj.mk depends on other-proj and is built as shared library.
Building this project works. However, modifying either my-proj.mk or other-proj.mk doesn’t trigger a rebuild of the respective project. Is there a way to do this?
I though I could list the makefiles as dependencies of Android.mk but I couldn’t figure out a way. (Listing them under LOCAL_SRC_FILES doesn’t work.)
I also read about $(call import-module,foo/bar) which seems to do exactly what I want. However, in this case I had to place the makefiles in a directory adjacent to the project directories (e.g. jni/makefiles/other-proj/Android.mk) but I couldn’t figure out how to specify the LOCAL_SRC_FILES. They don’t seem to like to be specified with an absolute path or with a .. inside the path. (I can’t place the makefiles directly in the sub project directories as they’re third-party projects.)
I figured out a way to do it, although not with simple includes but rather with
$(call import-module,foo/bar).First change, you need to decide on one of the sub projects being the main project. Let’s take
my-projfor that. Then the directory structure changes like this:Basically I renamed
my-proj.mkto/Android.mkandother-proj.mktoother-proj/Android.mk.The main
Android.mkthen changes to something like this:The
other-projis included in the last line.Note that the line before the last line sets the module path. Setting the module path from within the makefile via
does not work. (If
NDK_MODULE_PATHis to be used, it needs to be defined as an environment variable outside of the makefile).