2

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.

kushaldsouza
  • 710
  • 5
  • 12
  • 36
  • The NDK is a GCC toolchain, the normal GCC rules and options mostly apply. If you want help here, please be fully specific about the exact problem you are experiencing. Show the include statements, give the actual paths of the files not being found and of the source files where they are referenced, and show the compiler output. – Chris Stratton Mar 18 '14 at 16:26
  • And that file is found where? And referenced where, with what syntax? – Chris Stratton Mar 18 '14 at 16:43
  • Please post **absolute** paths for all the files in question – Chris Stratton Mar 18 '14 at 16:45
  • The absolute path to the external project is C:/projects/externalappsdk – kushaldsouza Mar 18 '14 at 16:47
  • @ChrisStratton Edited the question as requested. The included file is geos_c.h which is present in the folder that I have included in the LOCAL_C_INCLUDES as mentioned in the original question. – kushaldsouza Mar 18 '14 at 16:50
  • -1 If you are going to refuse to post the absolute path of **all files in question** we cannot help you sort out why your *relative* specifications are not working. – Chris Stratton Mar 18 '14 at 16:52
  • @ChrisStratton: I am relatively new to the NDK, which is why I am a little confused by your request. Shall edit the question with the absolute paths. But i am not sure what absolute paths, you require, I have provided the path to the headers I am linking against. – kushaldsouza Mar 18 '14 at 16:53
  • List the absolute path of the C file, the H file, and the Android.mk and post the include directive from the C file – Chris Stratton Mar 18 '14 at 16:53
  • Your question is *still* incomplete. Post the include directive from the C source file. – Chris Stratton Mar 18 '14 at 17:05

2 Answers2

1

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.

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
  • Thanks a lot for taking the time to recreate the project structure and this is exactly the directory structure that I am using. I already had the LOCAL_PATH := $(call my-dir) and I have edited the question to reflect this. I managed to resolve the issue using LOCAL_C_INCLUDES := ../../projects/externalappsdk/include instead of LOCAL_C_INCLUDES := ../../../projects/externalappsdk/include. – kushaldsouza Mar 18 '14 at 17:41
  • I was under the impression that setting LOCAL_PATH := $(call my-dir) would give the path of the Android.mk file which is within the jni folder as shown by your project structure. However, it seems as though, the current directory is the root of the project folder, i.e. "myandroidproject" in this case. This is also the folder from where I run my ndk-build command. I am not sure if this is being caused by any of the previous module declarations. Thanks once again. I shall mark this as the answer. – kushaldsouza Mar 18 '14 at 17:41
  • If it is not too much to ask, would you be able to shed some light on another issue I am having: http://stackoverflow.com/questions/22503274/android-ndk-module-that-is-dependant-on-another-module I made sure I provided detailed information :) – kushaldsouza Mar 19 '14 at 17:13
0

Use LOCAL_EXPORT_C_INCLUDE_DIRS instead of LOCAL_C_INCLUDES