@@ -42,17 +42,20 @@ public class NativeLibraryLoader {
42
42
static {
43
43
String libname = OBJECTBOX_JNI ;
44
44
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
+
45
50
// Some Android devices are detected as neither Android or Linux below,
46
51
// so assume Linux by default to always fallback to Android
47
52
boolean isLinux = true ;
48
53
// For Android, os.name is also "Linux", so we need an extra check
49
54
// Is not completely reliable (e.g. Vivo devices), see workaround on load failure
50
55
// Note: can not use check for Android classes as testing frameworks (Robolectric)
51
56
// may provide them on non-Android devices
52
- boolean android = System . getProperty ( "java. vendor" ) .contains ("Android" );
57
+ final boolean android = vendor .contains ("Android" );
53
58
if (!android ) {
54
- String osName = System .getProperty ("os.name" ).toLowerCase ();
55
- String sunArch = System .getProperty ("sun.arch.data.model" );
56
59
String cpuArchPostfix = "32" .equals (sunArch ) ? "-x86" : "-x64" ;
57
60
if (osName .contains ("windows" )) {
58
61
isLinux = false ;
@@ -70,27 +73,35 @@ public class NativeLibraryLoader {
70
73
checkUnpackLib (filename );
71
74
}
72
75
}
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 ());
83
83
}
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 ;
89
96
}
90
- } else {
91
- throw e ;
92
97
}
93
98
}
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 );
94
105
}
95
106
}
96
107
0 commit comments