couchbase_lite_dart icon indicating copy to clipboard operation
couchbase_lite_dart copied to clipboard

Unhandled Exception: Domain: 2, Code: 30, Message: Read-only file system

Open edityomurti opened this issue 3 years ago • 4 comments

I tried to run the example app on Android. After adding the prebuilt v0.4.0 Android shared libraries and it succeeded to run, I got the following exception.

Do I need to add something? Is it AndroidManifest write permission?

E/flutter (32305): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Domain: 2, Code: 30, Message: Read-only file system
E/flutter (32305): #0      validateError (package:couchbase_lite_dart/src/database_error.dart:25:5)
E/flutter (32305): #1      Database.open (package:couchbase_lite_dart/src/database.dart:138:5)
E/flutter (32305): #2      new Database (package:couchbase_lite_dart/src/database.dart:45:7)
E/flutter (32305): #3      main (package:couchbase_lite_dart_example/main.dart:14:12)
E/flutter (32305): #4      _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:142:25)
E/flutter (32305): #5      _rootRun (dart:async/zone.dart:1354:13)
E/flutter (32305): #6      _CustomZone.run (dart:async/zone.dart:1258:19)
E/flutter (32305): #7      _runZoned (dart:async/zone.dart:1789:10)
E/flutter (32305): #8      runZonedGuarded (dart:async/zone.dart:1777:12)
E/flutter (32305): #9      _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:138:5)
E/flutter (32305): #10     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:283:19)
E/flutter (32305): #11     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

edityomurti avatar Jul 14 '21 08:07 edityomurti

By default the database is created in the same folder where the app is run, which on Android is who knows what. You can use the path provider package to get the path to the documents directory, and pass it to the Database. I kept directory management out of the library on purpose so applications can set the directory depending on platform and business needs.

For Android something like this should work:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
   initializeCblC();

  var docPath = await getApplicationDocumentsDirectory();

  db = Database('appdb', directory: docPath.path);

  runApp(MyApp());
}```

Rudiksz avatar Jul 14 '21 14:07 Rudiksz

I recommend you use the v0.5.x releases for now.

Rudiksz avatar Jul 14 '21 14:07 Rudiksz

For Android something like this should work:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
   initializeCblC();

  var docPath = await getApplicationDocumentsDirectory();

  db = Database('appdb', directory: docPath.path);

  runApp(MyApp());
}```

Thanks @Rudiksz, it works.

Any idea what would it take to use this lib on a Flutter Web app ?

edityomurti avatar Jul 15 '21 10:07 edityomurti

I'm not aware of any mechanism to translate this library to javascript, considering it's native code.

Unless somebody writes a js version of couchbase lite (like PouchDB) or at least implements the sync gateway protocol for PouchDB, I see no way for couchbase lite making it to the web. And if at Couchbase itself are not interested, I doubt it will ever happen.

And even if there was one, there's still the issue of using it in a Flutter app.

Rudiksz avatar Jul 16 '21 08:07 Rudiksz