6

I have some two shared libraries and header for them. I want to build third shared library using functions from previous two libs. Have problem with makefile i think. When i try to build receive this:

Android NDK: /cygdrive/d/.../jni/Android.mk: Cannot find module with tag 'shared1' in import path
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?
Android NDK: The following directories were searched:
Android NDK:
/cygdrive/d/.../jni/Android.mk:36: *** Android NDK: Aborting.    .  Stop.

structure of my project:

jni/
 - myfile.c
 - Android.mk
   jni/dec/
     - lot of header files
   jni/enc/
     - lot of header files
libs/armeabi/
 - shared1.so
 - shared2.so

also Android.mk sourse:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_C_INCLUDES :=   \
    $(LOCAL_PATH)/dec \
    $(LOCAL_PATH)/enc 

LOCAL_SHARED_LIBRARIES := shared1 shared2

LOCAL_MODULE    := mylib
LOCAL_SRC_FILES := myfile.c
LOCAL_LDLIBS    += -lOpenSLES
LOCAL_LDLIBS    += -llog
LOCAL_LDLIBS    += -landroid

include $(BUILD_SHARED_LIBRARY)

$(call import-module, shared1)
$(call import-module, shared2)
Taras Mazepa
  • 604
  • 8
  • 24

2 Answers2

5

Take a look to this question: Android JNI APK Packing

You need to give another name for libs/armeabi/ folder to avoid conflicts with NDK build and add the following code before the include $(CLEAR_VARS) statement:

include $(CLEAR_VARS)
LOCAL_MODULE:=shared1
LOCAL_SRC_FILES:=3rdparty_libs/shared1.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE:=shared2
LOCAL_SRC_FILES:=3rdparty_libs/shared2.so
include $(PREBUILT_SHARED_LIBRARY)
Community
  • 1
  • 1
Andrey Kamaev
  • 29,582
  • 6
  • 94
  • 88
2

As I understand it, the correct method is to use ndk-build and not invoking the compiler directly.

In Android.mk you need to specify a module for each static library you want to compile, and then specify that your shared library should use it.

Example of a modified Android.mk file of the hello-jni sample project:

LOCAL_PATH := $(call my-dir)

# Define vars for library that will be build statically.
include $(CLEAR_VARS)
LOCAL_MODULE := <module_name>
LOCAL_C_INCLUDES := <header_files_path>
LOCAL_SRC_FILES :=  <list_of_src_files>

# Optional compiler flags.
LOCAL_LDLIBS   = -lz -lm
LOCAL_CFLAGS   = -Wall -pedantic -std=c99 -g

include $(BUILD_STATIC_LIBRARY)

# First lib, which will be built statically.
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_STATIC_LIBRARIES := <module_name>
LOCAL_C_INCLUDES := <header_files_path>
LOCAL_SRC_FILES := hello-jni.c

include $(BUILD_SHARED_LIBRARY)

If you want control over which modules to compile when you run ndk-build you can create create a Application.mk file (in the same directory as Android.mk) and list all the modules as in the following example:

APP_MODULES := <module_name_1> <module_name_2> ... <module_name_n>

I think it Helps you