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

Support custom library loader #10733

Merged
merged 1 commit into from
Jan 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}