objectbox / objectbox-dart

Flutter database for super-fast Dart object persistence
https://docs.objectbox.io/getting-started
Apache License 2.0
1.05k stars 120 forks source link

Unhandled Exception: StorageException: failed to create store: Could not open database environment; please check options and file system (1: Operation not permitted) (OBX_ERROR code 10199) #668

Closed rerosum closed 2 months ago

rerosum commented 2 months ago

Build info

Steps to reproduce

flutter run -d macos

Expected behavior

I expect the openStore method to not throw an exception.

Actual behavior

OB is unable to open the store. It does however create the lock file at this location: /Users/rerosum/Library/Containers/com.example.malgotrader/Data/Documents/obx-example total 16 drwxr-xr-x@ 3 rerosum staff 96 Aug 31 12:59 . drwx------ 3 rerosum staff 96 Aug 31 12:59 .. -rw-r--r--@ 1 rerosum staff 8128 Aug 31 12:59 lock.mdb

Code

/// Create an instance of ObjectBox to use throughout the app. static Future create() async { final docsDir = await getApplicationDocumentsDirectory(); // Future openStore() {...} is defined in the generated objectbox.g.dart final store = await openStore(directory: p.join(docsDir.path, "obx-example")); return ObjectBox._create(store); }

Stacktrace:

001-11:18:15.1078 [ERROR] Storage error "Operation not permitted" (code 1) [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: StorageException: failed to create store: Could not open database environment; please check options and file system (1: Operation not permitted) (OBX_ERROR code 10199) ObjectBoxNativeError.throwMapped (package:objectbox/src/native/bindings/helpers.dart:99:11) throwLatestNativeError (package:objectbox/src/native/bindings/helpers.dart:54:48) checkObxPtr (package:objectbox/src/native/bindings/helpers.dart:31:5) Store._checkStorePointer (package:objectbox/src/native/store.dart:451:7) new Store (package:objectbox/src/native/store.dart:274:7) openStore (package:malgotrader/objectbox.g.dart:150:14)

ObjectBox.create (package:malgotrader/utils/store.dart:18:19) main (package:malgotrader/main.dart:34:15)
rerosum commented 2 months ago

Issue was resolved by adding the key:

<key>com.apple.security.app-sandbox</key>
<false/>

to the macos/Runner/DebutProfile.entitlements

greenrobot-team commented 2 months ago

@rerosum This turns off the App sandbox, that's fine for development. When actually shipping an app, it might be necessary to configure a macOS application group. See the Store constructor API docs for details about it.