Calling System.loadLibrary twice for the same shared library

android, c++, java, java-native-interface

Solution

According to the apidocs it should not be a problem: "If this method is called more than once with the same library name, the second and subsequent calls are ignored."

Problem

I have the situation when two jar libraries use the same shared library. In each library "the main interface" class loads the .so file with `System.loadLibrary`. My question is: if the user decides to use these two jar libraries in one project, would the second call to `System.loadLibrary` for the same .so file cause any exception? Or is it "somehowe handled" by the system to prevent shared libraries from being loaded twice? Or maybe there is a "commonly known pattern" to handle such situations? The jni wrappers are targeted to be used on android. I am the author of both wrapper libs so answering you can assume full control on java sources.

Original source

Related problems