2

I have an Android library project 'A', which contains native C++ sources in the 'A/jni' folder which nicely build to a 'A/libs/armeabi-v7a/libA.so' and related for other platforms.

I now want to make an Android project 'B' which consists of Java stuff as well as more native C++ sources in the 'B/jni' folder. These sources use code from the C++ library of project 'A'. I have managed to compile these fine by setting my

 LOCAL_C_INCLUDES := (path_to_A/jni) 

(i.e. this picks up the header files from project 'A').

The question: how do I link to 'A/lib/armeabi-v7a/libA.so' in a clean way?

I have read the IMPORT_MODULE documentation, but that seems to be geared towards a situation in which you want to link to a pure-NDK module, not a library which sits inside an Android library project.

2 Answers 2

1

First create a module that will compile your libA.so library as prebuilt shared library in your project B.

include $(CLEAR_VARS) LOCAL_MODULE := libA LOCAL_SRC_FILES := path/to/libA.so include $(PREBUILT_SHARED_LIBRARY) 

Then, add this module to your main module of your project by:

LOCAL_SHARED_LIBRARIES := libA 

I have never tried IMPORT_MODULE option in my project but this works in my case.

Sign up to request clarification or add additional context in comments.

1 Comment

Just to complete this answer: in order for this to work, the environment variable NDK_MODULE_PATH needs to contain the location of the libA top level folder, and you need to add $(call import-module, libA) to the end of Android.mk for project B.
0

@Kasper: you say:

LOCAL_C_INCLUDES := (path_to_B/jni) 

Did you mean:

LOCAL_C_INCLUDES := (path_to_A/jni) 

?

1 Comment

Yes, sorry, now fixed.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.