Android Objectbox 版本 3.1.2
Flutter Objectbox 版本 1.4.1
Android 代码做读/写操作
Flutter 代码只做读操作
有时android端会抛出这个异常:
Could not renew tx(另一个读取事务在这个线程上仍然处于活动状态)(错误代码-30783)
当我仅使用 android 时,不会发生此异常。
安卓:
boxStore = MyObjectBox.builder().androidContext(application).build()
扑:
final documentDir = await getApplicationDocumentsDirectory();
var androidDir =
'${documentDir.parent.absolute.path}/files/objectbox/objectbox/';
var objectboxDir = Directory(androidDir);
var exists = await objectboxDir.exists();
if (!exists) {
objectboxDir.create(recursive: true);
}
store = await openStore(directory: androidDir);
回答1
拥有这两个库似乎是一个棘手的设置......你确定你在 Dart 中(或者在 Android 中)使用不同的线程(例如隔离)吗?因为错误“另一个读取事务在该线程上仍然处于活动状态”读起来更像是使用了同一个线程。在这种情况下,每个库的某些线程本地缓存会干扰另一个库。
因此,请确保不要在两个库上使用相同的线程。