Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

realm init bug #1809

Open
zhengxiaozhu opened this issue Nov 26, 2024 · 2 comments
Open

realm init bug #1809

zhengxiaozhu opened this issue Nov 26, 2024 · 2 comments

Comments

@zhengxiaozhu
Copy link

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)
#1 using (package:ffi/src/arena.dart:124)
#2 _raiseLastError (package:realm_dart/src/handles/native/error_handling.dart:48)
#3 PointerEx.raiseLastErrorIfNull (package:realm_dart/src/handles/native/error_handling.dart:16)
#4 new RealmHandle.open (package:realm_dart/src/handles/native/realm_handle.dart:48)
#5 Realm.openRealm (package:realm_dart/src/realm_class.dart:153)
#6 new Realm.
(package:realm_dart/src/realm_class.dart:119)
#7 new Realm (package:realm_dart/src/realm_class.dart:117)
#8 RealmService.init (package:xxx/utils/RealmService.dart:54)
#9 main (package:xxxx/main.dart:24)
#10 _runMain. (dart:ui/hooks.dart:301)
#11 _delayEntrypointInvocation. (dart:isolate-patch/isolate_patch.dart:297)
#12 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184)


It is strange that,Call the following code before I initialize it, and the error will disappear。

await getApplicationDocumentsDirectory();

Repro steps

Future main() async {
WidgetsFlutterBinding.ensureInitialized();
await RealmService.instance.init();
runApp(const MyApp());
}

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

@nirinchev
Copy link
Member

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.

@zhengxiaozhu
Copy link
Author

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 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants