2

Right now I am working on a native Android project and I want to use DevIL. I don't want to put all the NDK code into one file, since DevIL needs multiple other libraries (libpng/libjpeg/...) and the Android.mk would end up being bloated.

I created a sub directory called Devil in my jni directory. I put all the code needed for DevIl (+ the libraries) in this directory. I also created an extra Android.mk file in this directory. In my "main" Android.mk file I added$(call import-module,DevIL) as well as: LOCAL_SHARED_LIBRARIES += libdevil. In the DevIL Android.mk I created an libdevil module and I used LOCAL_EXPORT_C_INCLUDES to link to the DevIL header files. When I put #include into my main.cpp file the ndk-build fails and complains "No such file or directory" in regards to the included header. If I don't put the #include into the code, the code compiles fine and all the shared libraries are created and put into the libs folder. What am I doing wrong?

My Main Android.mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include cflags.mk

LOCAL_MODULE            := arm
LOCAL_SRC_FILES         := main.cpp
LOCAL_SHARED_LIBRARIES  += libdevil

include $(BUILD_SHARED_LIBRARY)

 $(call import-module,DevIL)

The Android.mk used for DevIl

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

include cflags.mk

JPEG_SRC_PATH       := Libjpeg/
DEVIL_SRC_PATH      := DevIL/
#many more 

#libjpeg
include $(CLEAR_VARS)

LOCAL_MODULE    := libjpeg
LOCAL_C_INCLUDES  :=  ${JPEG_SRC_PATH}
FILE_LIST := $(wildcard $(LOCAL_PATH)/JPEG_SRC_PATH/*.c)
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)

include $(BUILD_SHARED_LIBRARY)

#many other libraries; basically the same as libjpeg

#libdevil
 include $(CLEAR_VARS)

 LOCAL_MODULE    := libdevil
 LOCAL_EXPORT_C_INCLUDES  :=  \
                          ${DEVIL_SRC_PATH}include \
                          ${DEVIL_SRC_PATH}src-IL/include \
                          #many more 

 FILE_LIST := $(wildcard $(LOCAL_PATH)/DEVIL_SRC_PATHsrc-IL/src/*.c)
 LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
 LOCAL_STATIC_LIBRARIES := \
                        libjpeg \
                        #many more 
 LOCAL_LDLIBS    += -lz
 include $(BUILD_SHARED_LIBRARY)

The cflags.mk file

LOCAL_CFLAGS    := -DANDROID_NDK
LOCAL_CFLAGS    += -Werror          
LOCAL_CFLAGS    += -Wall
LOCAL_CFLAGS    += -Wextra
LOCAL_CFLAGS    += -Wno-strict-aliasing     
LOCAL_CFLAGS    += -Wno-unused-parameter
LOCAL_CFLAGS    += -Wno-missing-field-initializers  
LOCAL_CFLAGS    += -Wno-multichar   
LOCAL_CPPFLAGS := -Wno-type-limits
LOCAL_CPPFLAGS += -Wno-invalid-offsetof
LOCAL_CPPFLAGS += -std=c++11
LOCAL_CFLAGS    += -std=c++11
LOCAL_CFLAGS    += -fexceptions
LOCAL_CFLAGS += -Wno-error=deprecated-declarations

LOCAL_ARM_MODE := arm

Structure of the Directories

 jni
 |
 +-- main.cpp
 +-- Android.mk <- main Android
 +-- Application.mk
 +-- cflags.mk
 |
 +--DevIL
    |
    +-- Android.mk <- the Android.mk for DevIL
    +-- cflags.mk
    +--DevIL <-Directory containing DevIL source code 
    +--Libjpeg <-Directory containing code of specific  DevIL dependency
    +--...<-Directory containing code of specific DevIL dependency 

Edit:

I noticed that I did not add my Application.mk, thus my Application.mk

Application.mk

APP_PLATFORM := android-19
APP_ABI := armeabi-v7a
APP_STL:=c++_static
APP_LDFLAGS := -Wl,--build-id
NDK_TOOLCHAIN_VERSION := 4.9
ROOT_DIR := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
NDK_MODULE_PATH := $(ROOT_DIR)

1 Answers1

0

This does not answer the question, but if you are here from a search engine and happen to be having issues with LOCAL_EXPORT_C_INCLUDES on an AOSP module (not an NDK project!), Google's documentation at https://developer.android.com/ndk/guides/android_mk.html applies only to NDK projects.

For AOSP modules, the variable name is LOCAL_EXPORT_C_INCLUDE_DIRS, not LOCAL_EXPORT_C_INCLUDES.

jcjcc
  • 1
  • 1
  • Source? It's still the same after over 3 years. – vesperto Jan 29 '21 at 12:03
  • 1
    [`LOCAL_EXPORT_C_INCLUDES`](https://cs.android.com/search?q=LOCAL_EXPORT_C_INCLUDES) appears nowhere inside `build/make` except in a comment, whereas [`LOCAL_EXPORT_C_INCLUDE_DIRS`](https://cs.android.com/search?q=LOCAL_EXPORT_C_INCLUDE_DIRS) does. – jcjcc Jan 30 '21 at 15:43
  • @jcjcc The documentation is not incorrect because they refer to different things. The AOSP build system does not use the same build macros as `ndk-build`. For example, AOSP uses `BUILD_PREBUILT`, instead of `PREBUILT_STATIC_LIBRARY` or `PREBUILT_SHARED_LIBRARY`. – BLuFeNiX Feb 24 '22 at 18:49
  • 1
    @BLuFeNiX thanks, [you are absolutely correct](https://android.googlesource.com/platform/ndk.git/+/refs/heads/master/build/core/definitions.mk#253). Looking at Git history this was not something that changed since May 2017, so this answer has been wrong from the beginning. – jcjcc Feb 25 '22 at 22:24