Class NativeLoader


  • public class NativeLoader
    extends java.lang.Object
    Facade to load native libraries for android
    • Method Summary

      Modifier and Type Method Description
      static java.lang.String getLibraryPath​(java.lang.String shortName)
      Get the path of a loaded shared library.
      static int getSoSourcesVersion()
      Get the version of the loader used.
      static void init​(NativeLoaderDelegate delegate)
      Initializes native code loading for this app.
      static void initIfUninitialized​(NativeLoaderDelegate delegate)
      Perform an initialization only if NativeLoader has not already been initialized.
      static boolean isInitialized()
      Determine whether NativeLoader has already been initialized.
      static boolean loadLibrary​(java.lang.String shortName)  
      static boolean loadLibrary​(java.lang.String shortName, int flags)
      Load a shared library, initializing any JNI binding it contains.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • loadLibrary

        public static boolean loadLibrary​(java.lang.String shortName)
      • loadLibrary

        public static boolean loadLibrary​(java.lang.String shortName,
                                          int flags)
        Load a shared library, initializing any JNI binding it contains. Depending upon underlying loader, behavior can be customized based on passed in flag
        Parameters:
        shortName - Name of library to find, without "lib" prefix or ".so" suffix
        flags - 0 for default behavior, otherwise NativeLoaderDelegate defines other behaviors.
        Returns:
        Whether the library was loaded as a result of this call (true), or was already loaded through a previous call (false).
      • getLibraryPath

        public static java.lang.String getLibraryPath​(java.lang.String shortName)
                                               throws java.io.IOException
        Get the path of a loaded shared library.
        Parameters:
        shortName - Name of library to find, without "lib" prefix or ".so" suffix
        Returns:
        The path for the loaded library, null otherwise.
        Throws:
        java.io.IOException - IOException
      • getSoSourcesVersion

        public static int getSoSourcesVersion()
        Get the version of the loader used.
        Returns:
        The version number for the loader.
      • init

        public static void init​(NativeLoaderDelegate delegate)
        Initializes native code loading for this app. Should be called only once, before any calls to loadLibrary(String).
        Parameters:
        delegate - Delegate to use for all loadLibrary calls.
      • isInitialized

        public static boolean isInitialized()
        Determine whether NativeLoader has already been initialized. This method should not normally be used, because initialization should be performed only once during app startup. However, libraries that want to provide a default initialization for NativeLoader to hide its existence from the app can use this method to avoid re-initializing.
        Returns:
        True if init(NativeLoaderDelegate) has been called.
      • initIfUninitialized

        public static void initIfUninitialized​(NativeLoaderDelegate delegate)
        Perform an initialization only if NativeLoader has not already been initialized. This protects against race conditions where isInitialized and init are called by multiple threads and both threads end up trying to perform an initialization
        Parameters:
        delegate - the NativeLoaderDelegate