Disable UnsatisfiedLinkError during local tests (#3942)

This commit is contained in:
Adrian Cojocaru
2025-11-17 13:44:33 +02:00
committed by GitHub
parent cf44965d1f
commit e4457608cc
3 changed files with 38 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
package org.maplibre.android;
import org.maplibre.android.log.Logger;
import org.maplibre.android.utils.PlatformUtils;
/**
* Loads the mapbox-gl shared library
@@ -56,7 +57,7 @@ public abstract class LibraryLoader {
Logger.e(TAG, message, error);
MapStrictMode.strictModeViolation(message, error);
if (!handleLoadError) {
if (!handleLoadError && !PlatformUtils.isTest()) {
throw error;
}
}

View File

@@ -0,0 +1,35 @@
package org.maplibre.android.utils;
public class PlatformUtils {
public static boolean isTest() {
return isJUnit() || isRobolectric() || !isAndroid();
}
public static boolean isJUnit() {
try {
Class.forName("org.junit.Test");
return true;
} catch (ClassNotFoundException ignored) {
return false;
}
}
public static boolean isRobolectric() {
try {
Class.forName("org.robolectric.Robolectric");
return true;
} catch (ClassNotFoundException ignored) {
return false;
}
}
public static boolean isAndroid() {
try {
Class.forName("android.os.Build");
return true;
} catch (ClassNotFoundException ignored) {
return false;
}
}
}

View File

@@ -7,7 +7,7 @@ open class BaseTest {
@JvmStatic
@BeforeClass
fun setup() {
LibraryLoader.enableErrorHandling(true)
}
}
}