-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Closed
Labels
Description
PlatformDependent.resolveAndroidApiVersion() tries to determine the Android SDK version by reading the android.os.Build$VERSION#SDK_INT field:
try {
return (Integer) Class
.forName("android.os.Build$VERSION", true, getSystemClassLoader())
.getField("SDK_INT")
.get(null);
} catch (Exception e) {
// Can not resolve version of Android API, maybe current platform is not Android
// or API of resolving current Version of Android API has changed in some release of Android
return ANDROID_API_VERSION_IS_NOT_ANDROID;
}
When running under Robolectric, the class will be found (since Robolectric bundles an original android.jar). However, the method is using the system class loader for loading it (instead of the Robolectric instrumenting class loader), which will not instrument the class to run in the JVM. As a result, static initialization of the class fails with an UnsatisfiedLinkError when calling SystemProperties.get(), which calls native method native_get.
PlatformDependent.resolveAndroidApiVersion() should use the default class loader or discard UnsatisfiedLinkErrors (or all throwables).
Reactions are currently unavailable