Runtime.LoadLibrary(String) Method

Definition

Loads the native library specified by the libname argument.

[Android.Runtime.Register("loadLibrary", "(Ljava/lang/String;)V", "GetLoadLibrary_Ljava_lang_String_Handler")]
public virtual void LoadLibrary (string? libname);
[<Android.Runtime.Register("loadLibrary", "(Ljava/lang/String;)V", "GetLoadLibrary_Ljava_lang_String_Handler")>]
abstract member LoadLibrary : string -> unit
override this.LoadLibrary : string -> unit

Parameters

libname
String

the name of the library.

Attributes

Exceptions

if the library can not be loaded, either because it's not found or because there is something wrong with it.

Remarks

Loads the native library specified by the libname argument. The libname argument must not contain any platform specific prefix, file extension or path. If a native library called libname is statically linked with the VM, then the JNI_OnLoad_libname function exported by the library is invoked. See the JNI Specification for more details.

Otherwise, the libname argument is loaded from a system library location and mapped to a native library image in an implementation- dependent manner.

First, if there is a security manager, its checkLink method is called with the libname as its argument. This may result in a security exception.

The method System#loadLibrary(String) is the conventional and convenient means of invoking this method. If native methods are to be used in the implementation of a class, a standard strategy is to put the native code in a library file (call it LibFile) and then to put a static initializer: <blockquote>

static { System.loadLibrary("LibFile"); }

</blockquote> within the class declaration. When the class is loaded and initialized, the necessary native code implementation for the native methods will then be loaded as well.

If this method is called more than once with the same library name, the second and subsequent calls are ignored.

Java documentation for java.lang.Runtime.loadLibrary(java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to