Skip to content

Commit 1e93f36

Browse files
authored
Add support for Android <= 7.1.1
This pull request for the issue related to objectbox#187 Failed to load dynamic library (dlopen failed: library "libobjectbox-jni.so" not found)
1 parent 8481811 commit 1e93f36

File tree

1 file changed

+36
-23
lines changed

1 file changed

+36
-23
lines changed

flutter_libs/android/src/main/java/io/objectbox/objectbox_flutter_libs/ObjectboxFlutterLibsPlugin.java

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,42 @@
1010

1111
/** ObjectboxFlutterLibsPlugin */
1212
public class ObjectboxFlutterLibsPlugin implements FlutterPlugin, MethodCallHandler {
13-
/// The MethodChannel that will the communication between Flutter and native Android
14-
///
15-
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
16-
/// when the Flutter Engine is detached from the Activity
17-
private MethodChannel channel;
18-
19-
@Override
20-
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
21-
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "objectbox_flutter_libs");
22-
channel.setMethodCallHandler(this);
23-
}
24-
25-
@Override
26-
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
27-
if (call.method.equals("getPlatformVersion")) {
28-
result.success("Android " + android.os.Build.VERSION.RELEASE);
29-
} else {
30-
result.notImplemented();
13+
/// The MethodChannel that will the communication between Flutter and native Android
14+
///
15+
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
16+
/// when the Flutter Engine is detached from the Activity
17+
private MethodChannel channel;
18+
19+
@Override
20+
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
21+
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "objectbox_flutter_libs");
22+
channel.setMethodCallHandler(this);
23+
loadLibrary();
24+
}
25+
26+
@Override
27+
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
28+
if (call.method.equals("getPlatformVersion")) {
29+
result.success("Android " + android.os.Build.VERSION.RELEASE);
30+
} else {
31+
result.notImplemented();
32+
}
33+
}
34+
35+
@Override
36+
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
37+
channel.setMethodCallHandler(null);
3138
}
32-
}
3339

34-
@Override
35-
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
36-
channel.setMethodCallHandler(null);
37-
}
40+
private static boolean isLibraryLoaded = false;
41+
42+
private static void loadLibrary() {
43+
if (isLibraryLoaded) {
44+
return;
45+
}
46+
47+
// Loads `libobjectbox-jni.so`.
48+
System.loadLibrary("objectbox-jni");
49+
isLibraryLoaded = true;
50+
}
3851
}

0 commit comments

Comments
 (0)