Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Support custom LibraryLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
jaegs authored and tobrun committed Jan 2, 2018
1 parent 4709bf0 commit a56b51c
Showing 1 changed file with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,46 @@
import timber.log.Timber;

/**
* Centralises the knowledge about "mapbox-gl" library loading.
* Loads the mapbox-gl shared library
* <p>
* By default uses the {@link System#loadLibrary(String)},
* use {@link #setLibraryLoader(LibraryLoader)} to provide an alternative library loading hook.
* </p>
*/
public class LibraryLoader {
public abstract class LibraryLoader {

private static final LibraryLoader DEFAULT = new LibraryLoader() {
@Override
public void load(String name) {
System.loadLibrary(name);
}
};

private static volatile LibraryLoader loader = DEFAULT;

/**
* Set the library loader that loads the shared library.
*
* @param libraryLoader the library loader
*/
public static void setLibraryLoader(LibraryLoader libraryLoader) {
loader = libraryLoader;
}

/**
* Loads "libmapbox-gl.so" native shared library.
* <p>
* Catches UnsatisfiedLinkErrors and prints a warning to logcat.
* </p>
*/
public static void load() {
try {
System.loadLibrary("mapbox-gl");
loader.load("mapbox-gl");
} catch (UnsatisfiedLinkError error) {
Timber.e(error, "Failed to load native shared library.");
}
}

public abstract void load(String name);
}

0 comments on commit a56b51c

Please sign in to comment.