I have a Java library for Android which I distribute to third party developers, and I want to embed a C library in it. I've added the library to the project via CMake:
add_library(wrapper SHARED wrap.c)
target_link_libraries(wrapper CLibraryTarget)
To the library's build.gradle I've added:
apply plugin: 'com.android.library'
...
android {
defaultConfig {
...
externalNativeBuild {
cmake {
cppFlags ""
targets "wrapper",
"CLibraryTarget"
}
}
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.0+"
}
}
}
In the library, I load the C library with:
public class Wrapper {
static {
System.loadLibrary("wrapper");
}
...
}
I'm trying to run a unit test to test some of the Java functions which wrap the C functions, and I get the exception:
java.lang.UnsatisfiedLinkError: no wrapper in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1871)
...
This works when I'm linking the C library in an App, but doesn't seem to work in a Java library. Why is the library not loaded? What do I need to do to embed the C library in a Java library for distribution? I can't seem to find any documentation specific to this scenario.