Question

I am using the Android NDK to build a shared library. I have include a snippet from my Android.mk file that is causing me a few issues.

LOCAL_PATH := $(call my-dir)

..#other module here
..#other module here

include $(CLEAR_VARS)
LOCAL_MODULE    := spatialite
LOCAL_C_INCLUDES := ../../../projects/externalappsdk/include
LOCAL_SRC_FILES := sqlite3.c \
spatialite.c
include $(BUILD_SHARED_LIBRARY)

My spatialite.c file includes some header files that are located in a folder that is external to the application project folder. I have included that folder in LOCAL_C_INCLUDES as shown above, but on running ndk-build, it still cannot locate these includes. What is the correct way of allowing the ndk-build command to identify where these includes are located. Any help will be greatly appreaciated.

UPDATE:

I wanted to add that spatialite itself need not be visible to the Java layer. I will thereafter be building another module which uses spatialite. I am not sure if this makes a difference to the way I declare the module on the Android.mk file.

The compiler output is shown below: jni/spatialite.c:102:20: fatal error: geos_c.h: No such file or directory #include

The .h file that is being imported in spatialite.c is located at C:/projects/externalappsdk/include. The spatialite.c and Android.mk are located at C:/mobile/myandroidproject/jni/

The include directive within my spatialite.c file is shown below:

#ifndef OMIT_GEOS   /* including GEOS */
#include <geos_c.h>
#endif

ANSWER: I managed to get this working using help from the answers provided by Chris which I have accepted. However, I had to make one change to the Android.mk file as is shown below:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := spatialite
LOCAL_C_INCLUDES := ../../projects/externalappsdk/include
LOCAL_SRC_FILES := sqlite3.c \
spatialite.c
include $(BUILD_SHARED_LIBRARY)

Note, that the LOCAL_C_INCLUDES goes two levels back instead of three.

Was it helpful?

Solution

Without a

LOCAL_PATH := $(call my-dir)

At the top of the Android.mk, I was unable to build a replica of your project as described, however the error was different than your report - without that directive the compiler was searching for the C source files in an NDK system directory rather in the jni/ folder.

$ cd mobile/myandroidproject/jni
$ ndk-build
Compile thumb  : spatialite <= spatialite.c
SharedLibrary  : libspatialite.so
Install        : libspatialite.so => libs/armeabi/libspatialite.so

File: ./mobile/myandroidproject/jni/Android.mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := spatialite
LOCAL_C_INCLUDES := ../../../projects/externalappsdk/include
LOCAL_SRC_FILES := sqlite3.c \
spatialite.c
include $(BUILD_SHARED_LIBRARY)

File: ./mobile/myandroidproject/jni/spatialite.c

#include <geos_c.h>

File: ./mobile/myandroidproject/jni/sqlite3.c

//empty file

File: ./projects/externalappsdk/include/geos_c.h

//empty file

At minimum you should add the LOCAL_PATH line to your Android.mk

If that does not solve the problem, then please update your question with any differences between your project structure and my recreation of it.

OTHER TIPS

Use LOCAL_EXPORT_C_INCLUDE_DIRS instead of LOCAL_C_INCLUDES

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top