0

In our Android project, we have several tens of C and CPP files which we #include through one container file for the build. The container file is listed in LOCAL_SRC_FILES, since that's what's compiled. However, when I edit one of the included .cpp files, that doesn't seem to trigger a build.

If I were in total control of the make file, I'd just include all those files as dependencies for the relevant compile step. However, android.mk handles making all those compile dependencies in general, so I don't know where to insert them.

Ethan Bradford
  • 710
  • 8
  • 10
  • I could have had some other problem. I now get rebuilding when I edit one of the included files. – Ethan Bradford Jan 12 '20 at 05:36
  • How does Android react if you add the container file AND all the files it includes to the module configuration? – Simpl Jan 14 '20 at 10:27
  • I assumed, though I didn't check, that if list my individual files as LOCAL_SRC_FILES, they'd be directly compiled. There was probably something else going on here, though; now I do get a rebuild when I edit those files, so probably they were discovered through the include file discovery. – Ethan Bradford Jan 15 '20 at 15:58

2 Answers2

0

I have a three CPP file in this path

..src\main\cpp

  • mainClass.cpp
  • native-handler.h
  • native-handler.cpp

And I include to in android.mk file like this

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libjson-c
LOCAL_SRC_FILES :=  ../prebuild/libjson/$(TARGET_ARCH_ABI)/libjson-c.a
LOCAL_EXPORT_C_INCLUDES := ../prebuild/include
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := libcurl
LOCAL_SRC_FILES := ../prebuild/libcurl/$(TARGET_ARCH_ABI)/libcurl.a
LOCAL_EXPORT_C_INCLUDES := ../prebuild/include
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := Native
LOCAL_SRC_FILES := ../cpp/mainClass.cpp ../cpp/native-handler.cpp
LOCAL_C_INCLUDES := ../cpp/native-handler.h ../prebuild/include/json-c/json.h ../prebuild/include/curl/curl.h
LOCAL_LDLIBS := -lz -llog -ljnigraphics
LOCAL_STATIC_LIBRARIES := libjson-c libcurl
include $(BUILD_SHARED_LIBRARY)
Praful Korat
  • 374
  • 4
  • 22
0

Android.mk offers some features that Android.bp/Soong deliberately avoids (e.g. include files from parent directories). The goal of Soong is to completely replace the Android.mk based build system eventually. So if you happen to find a solution that works with Android.mk files you might have the same problem again in a future Android release.

The Android build system will detect changes to all files specified (e.g. as LOCAL_SRC_FILES in Android.mk or srcs in Android.bp) and trigger a rebuild of the module. I guess you have to switch to adding all source files that your container file included to the module configuration.

Simpl
  • 1,938
  • 1
  • 10
  • 21