1

I am unable to locate a working example of the Android NDK's module importation feature. The following Android.mk files seem correct, and the inner module builds and executes without error. However, building the outer module fails with the following error messages:

Android NDK: jni/inner/Android.mk:inner: LOCAL_MODULE_FILENAME should not include file extensions
Android NDK: jni/inner/Android.mk:inner: LOCAL_MODULE_FILENAME must not contain a file extension
/home/caleb/dev/android-ndk-r8e/build/core/build-shared-library.mk:30: * Android NDK: Aborting . Stop.

The inner, contained Android.mk file:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := inner
LOCAL_MODULE_FILENAME := libinner
LOCAL_SRC_FILES := inner-module.c

include $(BUILD_SHARED_LIBRARY)

The outer, containing Android.mk file:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := outer

$(call import-module,inner)

LOCAL_SHARED_LIBRARIES += inner

include $(BUILD_SHARED_LIBRARY)
cqcallaw
  • 1,463
  • 3
  • 18
  • 29
  • Have you declared NDK_MODULE_PATH? If so, what's it? – ozbek May 28 '13 at 05:34
  • NDK_MODULE_PATH is declared and set to "jni", which is the directory in which the inner module is located. If I unset NDK_MODULE_PATH, I get a different error, indicating the build system was unable to locate the inner module. – cqcallaw May 28 '13 at 14:14

2 Answers2

4

Try placing the call to import-module at the end of your outer file. It is not a must to place it before referencing 'inner', and the NDK documentation actually advice you to place it at the end.

eddiecohen
  • 41
  • 2
2

There's a few problems with what you are doing so here is how things should look.

The inner, contained Android.mk file:

# save away the previous local path
INNER_SAVED_LOCAL_PATH := $(LOCAL_PATH)

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := inner
LOCAL_MODULE_FILENAME := libinner
LOCAL_SRC_FILES := inner-module.c

include $(BUILD_SHARED_LIBRARY)
# at this point LOCAL_MODULE_FILENAME will have been auto
#  set to libinner.so or similar by the call to BUILD_SHARED_LIBRARY

# restore previous local path
LOCAL_PATH := $(INNER_SAVED_LOCAL_PATH)

The outer, containing Android.mk file:

LOCAL_PATH := $(call my-dir)

$(call import-module,inner)
# at this point
#  a) we've still got the correct LOCAL_PATH as we didn't trash it in
#     the included Android.mk file
#  b) LOCAL_MODULE_FILENAME is still set to libinner.so which if not
#     unset will cause BUILD_SHARED_LIBRARY to complain

include $(CLEAR_VARS)
# we've now got a clean slate

LOCAL_MODULE := outer

# the build system has 'remembered' the inner module
LOCAL_SHARED_LIBRARIES += inner

include $(BUILD_SHARED_LIBRARY)

I'm not sure if this is the way to do it but it works for me :)

user2746401
  • 3,157
  • 2
  • 21
  • 46