Throw exception on System.loadLibrary fail (#3916)

This commit is contained in:
Adrian Cojocaru
2025-10-31 15:53:24 +02:00
committed by GitHub
parent 73595014b1
commit 76da093e5e
49 changed files with 119 additions and 48 deletions

View File

@@ -20,6 +20,7 @@ public abstract class LibraryLoader {
private static volatile LibraryLoader loader = DEFAULT;
private static boolean loaded;
private static boolean handleLoadError = false;
/**
* Set the library loader that loads the shared library.
@@ -30,10 +31,17 @@ public abstract class LibraryLoader {
loader = libraryLoader;
}
/**
* Catch UnsatisfiedLinkErrors on load
*/
public static void enableErrorHandling(boolean value) {
handleLoadError = value;
}
/**
* Loads "libmaplibre.so" native shared library.
* <p>
* Catches UnsatisfiedLinkErrors and prints a warning to logcat.
* Catches UnsatisfiedLinkErrors (if enabled) and prints a warning to logcat.
* </p>
*/
public static synchronized void load() {
@@ -47,6 +55,10 @@ public abstract class LibraryLoader {
String message = "Failed to load native shared library.";
Logger.e(TAG, message, error);
MapStrictMode.strictModeViolation(message, error);
if (!handleLoadError) {
throw error;
}
}
}