11

I have a Android Studio (2.3) project with 2 modules, using CMake for native code.

Project --> Module1 (app): java + native JNI-wrapper, linking to libnative.so --> Module2 (libnative): native c++ code, producing libnative.so 

What is the preferred way to link libnative.so (build by Module2) into the JNI-wrapper in Module1? I currently use...

Module1-CMakeLists.txt:

add_library( native SHARED IMPORTED ) set_target_properties( jniwrapper PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/../libnative/build/intermediates/cmake/${BUILD_TYPE}/obj/${ANDROID_ABI}/libnative.so ) 

...where BUILD_TYPE is set in Module1's build.gradle, depending on the build type.

This works if I use "Make Module 'Module2'" in AS before building the full project. However, it seems rather inelegant to fetch the library out of gradle's building folder-hierarchy.

The alternative seemed to be to instruct Module2's CMakeLists.txt to install the file into Module1's lib-directory and import from there. But CMake seems to ignore the install command.

(I'm aware that I could just put the modules together under one tree.)

Thanks!

1 Answer 1

2

The alternative is as below: (Module2 CMakeLists.txt)

set_target_properties(${SHARED_LIBRARY_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "<your-prefered-directory>/jniLibs/${ANDROID_ABI}") 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.