Open zhengxiaozhu opened 1 day ago
Can you try to specify an explicit path for the config on Android? Seems like for some reason it gets resolved to the root of the filesystem and naturally, your app doesn't have permissions to write there.
Can you try to specify an explicit path for the config on Android? Seems like for some reason it gets resolved to the root of the filesystem and naturally, your app doesn't have permissions to write there.
If I specify the default path, does it mean that the data in the user's phone will be lost? Thank you for your reply 😁
What happened?
When I initialize realm。 My code looks like this
final config = Configuration.local([ xxx.schema, ]); _realm = Realm(config);
When I don't specify a path,It works on the emulator and on the iphone.But on Android phones, you get an error。This error is random,The odds are about 80 percent。Errors are as follows。[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: RealmException: Failed to open file at path './default.realm.lock': Read-only file system. Error code: realm_errno.RLM_ERR_FILE_PERMISSION_DENIED.
0 _raiseLastError. (package:realm_dart/src/handles/native/error_handling.dart:59)
It is strange that,Call the following code before I initialize it, and the error will disappear。
await getApplicationDocumentsDirectory();
Repro steps
1. Future main() async {
WidgetsFlutterBinding.ensureInitialized();
await RealmService.instance.init();
runApp(const MyApp());
}
2. class RealmService{
RealmService._privateConstructor();
static final RealmService _instance = RealmService._privateConstructor();
static RealmService get instance => _instance;
late Realm _realm;
Realm get realm => _realm;
Future init() async {
final config = Configuration.local([
xxxx.schema
]);
_realm = Realm(config);
}
void close() { _realm.close(); }
}
Version
3.24
What Atlas Services are you using?
-- select --
What type of application is this?
Flutter Application
Client OS and version
android
Code snippets
No response
Stacktrace of the exception/crash you're getting
No response
Relevant log output
No response