OverseerCouncil
OverseerCouncil

Reputation: 1

Can i load a dynamic library using JNI in a android native activity?

I am trying to create an application that uses Android Native Activity in order to avoid explosing my function code in java, but i meet a problem that i also want to use my another written dynamic library which uses JNI. I want to know whether i can load such a dynamic library in native activity or not. It seems like that dlopen() can not perform well. Can i use reflection to call System.loadlibrary(), or indeed there exist some dramatic way to solve it? Thank you for any help you can offer.

Upvotes: -1

Views: 215

Answers (1)

George Shakula
George Shakula

Reputation: 61

NativeActivity gives you all you need to use JNI. You should be able to load your library using dlopen:

dlopen("libname.so", RTLD_LAZY | RTLD_LOCAL)

Make sure to call JNI_OnLoad/JNI_OnUnload if your library has any. This will mimic what System.loadLibrary Java function does.

I have used JNI libraries and Java libraries from NativeActivity-based apps. So if you experience any particular problem with dlopen in this environment, feel free to open a separate question with more detail.

Upvotes: 1

Related Questions