Search code examples
androidandroid-ndkjava-native-interfacedlopen

Difference between dlopen and System.loadLibrary()


In Android, is there a difference between a library loaded using System.loadLibrary() in Java and a library loaded using dlopen() in native code? Can I just call a function in the dynamically loaded library directly the standard way through JNI, or do I have to retrieve the functions using dlsym() and create a bunch of stubs?


Solution

  • System.loadLibrary() loads a library in the Dalvik VM, dlopen() simply loads the library in you native process. If you want to access your library from Java, you need to write some glue JNI code. How you implement those is not important: you can link directly, or use dlopen(), etc.