Skip to content

Commit c659fa9

Browse files
Binding: check for lib using providesSymbol instead of except. (GH-252)
1 parent 31de197 commit c659fa9

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

objectbox/lib/src/native/bindings/bindings.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ ObjectBoxC? _tryObjectBoxLibProcess() {
1919
// [DynamicLibrary.process()] is not supported on windows, see its docs.
2020
if (Platform.isWindows) return null;
2121

22-
ObjectBoxC? obxc;
2322
try {
24-
_lib = DynamicLibrary.process();
25-
obxc = ObjectBoxC(_lib!);
26-
_isSupportedVersion(obxc); // may throw in case symbols are not found
27-
return obxc;
23+
final lib = DynamicLibrary.process();
24+
// Check if the library is actually loaded by searching for a common function.
25+
// Note: not using 'lookup' as its exception if not found is caught if
26+
// All Exceptions is enabled in VS Code.
27+
if (lib.providesSymbol('obx_version_is_at_least')) {
28+
_lib = lib;
29+
return ObjectBoxC(lib);
30+
} else {
31+
return null;
32+
}
2833
} catch (_) {
2934
// ignore errors (i.e. symbol not found)
3035
return null;

0 commit comments

Comments
 (0)