link dependent android ndk cmake project to main android ndk library project

338 views Asked by At

I have 2 modules in this project: app and libdatacpp libdatacpp is mainly a C++ project but uses some java code app is mainly a java project, but uses some c++ code

Structure of the project

When building the project, I get c++ linker errors for undefined functions from libdatacpp, because the app project doesn't link libDataCpp.o

In my cmake for app, I am linking against libDataCpp like this:

target_link_libraries(
        native-lib
        DataCpp)

I also link against the other project in the app module's build.gradle like this:

dependencies {
    api project(':libdatacpp')

How can I get the app module to automatically link against my libdatacpp module?

1

There are 1 answers

9
Mykola Khyliuk On

If you intend to provide libdatacpp native library for other AndroidStudio projects through .aar, then you need to use prefab feature.

But if these native library is part of your own project, then I don't see the need to put it in the .aar, just put its stuff (sources and CMakeLists.txt) in a subfolder and add it to build by using add_subdirectory (datacpp) in your main CMake.