Create a shared library linked to another non-standard shared libarary

I have two shared libraries and a title for them. I want to create a third shared library using functions from the previous two libraries. I have a problem with makefile, I think. When I try to build, we get the following:

  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) 
+6
source share
2 answers

Take a look at this question: Android JNI APK Packing

You need to specify a different name for the libs/armeabi/ folder to avoid conflicts with the NDK assembly and add the following code before the include $(CLEAR_VARS) :

 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) 
+5
source

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

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

An example of a modified Android.mk file in the hello-jni project example:

 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 to control which modules to compile when you run ndk-build, you can create the 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

+2
source

Source: https://habr.com/ru/post/909744/


All Articles