I am trying to import and use .so file in android studio NDK project. I have read the documentation of android studio, different blog, and answers on StackOverflow but none is working for me because most of them are outdated ( written or asked 3-4 year ago ). Also unable to follow the documentation.
Please Help!
(I'm assuming that the .so file is built for Android using the Android NDK. If not, this isn't going to work and you'll need the source to rebuild the .so file using the Android NDK)
Let's say that you've got a library named native-lib that was built for the ARMv7A architecture, and you've placed it in app/prebuilt_libs/armeabi-v7a/.
app/build.gradle:
app/CMakeLists.txt
If the library is meant to be used from Java
CallNative.java:
For example, if the native library has a function
JNIEXPORT jstring JNICALL Java_com_example_bar_MyClass_myNativeFunction
, then the Java class would have to be namedMyClass
and be in the packagecom.example.bar
.If the library is meant to be used by other native libraries
You'll need a header file (
*.h
) for the library. If you don't have one you'll have to figure out yourself how to write one.Then add this in your CMakeLists.txt:
And for the other native library that uses libnative-lib.so: