@@ -42,17 +42,20 @@ public class NativeLibraryLoader {
4242 static {
4343 String libname = OBJECTBOX_JNI ;
4444 String filename = libname + ".so" ;
45+
46+ final String vendor = System .getProperty ("java.vendor" );
47+ final String osName = System .getProperty ("os.name" ).toLowerCase ();
48+ final String sunArch = System .getProperty ("sun.arch.data.model" );
49+
4550 // Some Android devices are detected as neither Android or Linux below,
4651 // so assume Linux by default to always fallback to Android
4752 boolean isLinux = true ;
4853 // For Android, os.name is also "Linux", so we need an extra check
4954 // Is not completely reliable (e.g. Vivo devices), see workaround on load failure
5055 // Note: can not use check for Android classes as testing frameworks (Robolectric)
5156 // may provide them on non-Android devices
52- boolean android = System . getProperty ( "java. vendor" ) .contains ("Android" );
57+ final boolean android = vendor .contains ("Android" );
5358 if (!android ) {
54- String osName = System .getProperty ("os.name" ).toLowerCase ();
55- String sunArch = System .getProperty ("sun.arch.data.model" );
5659 String cpuArchPostfix = "32" .equals (sunArch ) ? "-x86" : "-x64" ;
5760 if (osName .contains ("windows" )) {
5861 isLinux = false ;
@@ -70,27 +73,35 @@ public class NativeLibraryLoader {
7073 checkUnpackLib (filename );
7174 }
7275 }
73- File file = new File (filename );
74- if (file .exists ()) {
75- System .load (file .getAbsolutePath ());
76- } else {
77- if (!android ) {
78- System .err .println ("File not available: " + file .getAbsolutePath ());
79- }
80- try {
81- if (!android || !loadLibraryAndroid (libname )) {
82- System .loadLibrary (libname );
76+ try {
77+ File file = new File (filename );
78+ if (file .exists ()) {
79+ System .load (file .getAbsolutePath ());
80+ } else {
81+ if (!android ) {
82+ System .err .println ("File not available: " + file .getAbsolutePath ());
8383 }
84- } catch (UnsatisfiedLinkError e ) {
85- if (!android && isLinux ) {
86- // maybe is Android, but check failed: try loading Android lib
87- if (!loadLibraryAndroid (OBJECTBOX_JNI )) {
88- System .loadLibrary (OBJECTBOX_JNI );
84+ try {
85+ if (!android || !loadLibraryAndroid (libname )) {
86+ System .loadLibrary (libname );
87+ }
88+ } catch (UnsatisfiedLinkError e ) {
89+ if (!android && isLinux ) {
90+ // maybe is Android, but check failed: try loading Android lib
91+ if (!loadLibraryAndroid (OBJECTBOX_JNI )) {
92+ System .loadLibrary (OBJECTBOX_JNI );
93+ }
94+ } else {
95+ throw e ;
8996 }
90- } else {
91- throw e ;
9297 }
9398 }
99+ } catch (UnsatisfiedLinkError e ) {
100+ String message = String .format (
101+ "Loading ObjectBox native library failed: vendor=%s,os=%s,arch=%s,android=%s,linux=%s" ,
102+ vendor , osName , sunArch , android , isLinux
103+ );
104+ throw new RuntimeException (message , e );
94105 }
95106 }
96107
0 commit comments