Skip to content

[ERROR] Flutter desktop macOS: Storage error "Operation not permitted" (code 1) #248

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

Closed
jochendev opened this issue May 19, 2021 · 16 comments · Fixed by #265
Closed

[ERROR] Flutter desktop macOS: Storage error "Operation not permitted" (code 1) #248

jochendev opened this issue May 19, 2021 · 16 comments · Fixed by #265
Labels
bug Something isn't working

Comments

@jochendev
Copy link

  • ObjectBox version: 1.0.0
  • Flutter/Dart SDK: 2.0.6
  • Null-safety enabled: yes
  • Reproducibility: always
flutter run

Running "flutter pub get" in untitled...                         1,220ms
Launching lib/main.dart on macOS in debug mode...
Running pod install...                                           1,395ms
Building macOS application...                                           
001-10:23:16.4099 [ERROR] Storage error "Operation not permitted" (code 1)
[ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: ObjectBoxException: failed to create store: 10199 Could not open database environment; please check options and file system (1: Operation not permitted)
#0      ObjectBoxNativeError.throwMapped (package:objectbox/src/native/bindings/helpers.dart:78:9)
#1      throwLatestNativeError (package:objectbox/src/native/bindings/helpers.dart:50:48)
#2      checkObxPtr (package:objectbox/src/native/bindings/helpers.dart:32:5)
#3      new Store (package:objectbox/src/native/store.dart:105:7)
#4      _MyHomePageState.initState.<anonymous closure> (package:untitled/main.dart:63:20)
#5      _rootRunUnary (dart:async/zone.dart:1362:47)
#6      _CustomZone.runUnary (dart:async/zone.dart:1265:19)
#7      _FutureListener.handleValue (dart:async/future_impl.dart:152:18)
#8      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:704:45)
#9      Future._propagateToListeners (dart:async/future_impl.dart:733:32)
#10     Future._completeWithValue (dart:async/future_impl.dart:539:5)
#11     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:254:13)
#12     getTemporaryDirectory (package:path_provider/path_provider.dart)
<asynchronous suspension>

Syncing files to device macOS...                                    88ms

Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h Repeat this help message.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).
An Observatory debugger and profiler on macOS is available at: http://127.0.0.1:59804/kwcL1lLkKYA=/

Flutter DevTools, a Flutter debugger and profiler, on macOS is available at: http://127.0.0.1:9106?uri=http%3A%2F%2F127.0.0.1%3A59804%2FkwcL1lLkKYA%3D%2F

💪 Running with sound null safety 💪

import 'package:flutter/material.dart';
import 'package:objectbox/objectbox.dart';
import 'package:path_provider/path_provider.dart';

import 'objectbox.g.dart';

@Entity()
class Note {
  int id;

  String text;
  String? comment;
  DateTime date;

  Note(this.text, {this.id = 0, this.comment, DateTime? date})
      : date = date ?? DateTime.now();
}

void main() {
  runApp(MyHomePage());
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  void initState() {
    super.initState();
    getTemporaryDirectory().then((value) {
      var _store =
          Store(getObjectBoxModel(), directory: value.path + '/objectbox');
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

flutter doctor -v
[✓] Flutter (Channel stable, 2.0.6, on macOS 11.3.1 20E241 darwin-arm, locale zh-Hans)
    • Flutter version 2.0.6 at /Users/jochen/Documents/dev/flutter
    • Framework revision 1d9032c7e1 (3 weeks ago), 2021-04-29 17:37:58 -0700
    • Engine revision 05e680e202
    • Dart version 2.12.3
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/jochen/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.5, Build version 12E262
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

[✓] VS Code (version 1.56.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 11.3.1 20E241 darwin-arm
    • Chrome (web)    • chrome • web-javascript • Google Chrome 90.0.4430.212
@jochendev jochendev added the bug Something isn't working label May 19, 2021
@vaind vaind changed the title [ERROR] Storage error "Operation not permitted" (code 1) [ERROR] Flutter desktop macOS: Storage error "Operation not permitted" (code 1) May 19, 2021
@vaind
Copy link
Contributor

vaind commented May 19, 2021

Thanks for bumping this to a standalone issue out of #166 - I'll repeat my last comment from there:

I was able to reproduce the macOS issue and indeed it tries to write to the right directory. I've made sure the directory exists so it was only supposed to create files but the issue was still the same. I suspect this has something to do with the app being sandboxed so objectbox-core doesn't have the right permissions to create the database properly. I'll discuss internally and I've noticed there're some docs about this for objectbox-swift: https://swift.objectbox.io/advanced/macos - not sure if any of that applies.

@AncientPixel
Copy link

Thanks for bumping this to a standalone issue out of #166 - I'll repeat my last comment from there:

I was able to reproduce the macOS issue and indeed it tries to write to the right directory. I've made sure the directory exists so it was only supposed to create files but the issue was still the same. I suspect this has something to do with the app being sandboxed so objectbox-core doesn't have the right permissions to create the database properly. I'll discuss internally and I've noticed there're some docs about this for objectbox-swift: https://swift.objectbox.io/advanced/macos - not sure if any of that applies.

I followed the steps on the supplied link but still get the same error as original poster reported.

@greenrobot
Copy link
Member

There's a macOS specific section in the Flutter Desktop docs: https://flutter.dev/desktop#macos-specific-support

Haven't tried yet, but seems like a different approach...

@AncientPixel
Copy link

Thanks for that link, I've updated the following lines to FALSE in my DebugProfile.entitlements and Release.entitlements file:
<key>com.apple.security.app-sandbox</key> <false/>
It is now working.

@vaind
Copy link
Contributor

vaind commented May 21, 2021

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

However, that means you won't be able to distribute the app through app store, right?

@TeddyLourson
Copy link

I did the same thing and turned off app-sandbox temporary so I can continue working on my app but I will have to enable it when it's done. From what I understood it's a special security thing from Apple that doesn't allow you to write/read files outside of your app's container folder without the user's consent. But no matter the path I'm giving to ObjectBox it keeps throwing me this error while just creating a simple file at that same path works.

@vaind
Copy link
Contributor

vaind commented May 21, 2021

Yeah, I'm 99.9 % sure it's not about the path but some of the other native API calls that are being executed during store setup. We'll have to take app-sandboxing as a known limitation for now until we figure out what permissions to set up so that it works. And I'm pretty sure it will, since the same native code is used for objectbox-swift...

@greenrobot
Copy link
Member

The com.apple.security.cs.disable-library-validation entitlement is a candidate for causing the error:

This security-hardening feature prevents a program from loading frameworks, plug-ins, or libraries unless they’re either signed by Apple or signed with the same Team ID as the main executable.

Not exactly sure what Flutter does with the ObjectBox lib; depending on that there may be a mismatch...

Maybe someone likes to try this entitlement and report back?

@TeddyLourson
Copy link

I just tried it, but I still get the exception.

@sunilpandit2
Copy link

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

problem solved

@greenrobot-team
Copy link
Member

@sunilpandit2 For development this is fine. But to build a release app, you might want to set a macosApplicationGroup as described in the Store docs.

@sunilpandit2
Copy link

sunilpandit2 commented Apr 22, 2024 via email

@PLGuerraDesigns
Copy link

PLGuerraDesigns commented Oct 16, 2024

This works for me:

<key>com.apple.security.files.downloads.read-write</key>
<true/>

Update in DebugProfile.entitlements and Release.entitlements

@Shashwat2708
Copy link

Shashwat2708 commented Jan 22, 2025

@greenrobot-team I opened runner in xcode and in signing and capabilities added "App Groups".
When i clicked on "+", it added my team id and automatically added the lines mentioned in the link you gave in my .entitlements file.

Still it did not work. Did I do it right or do I have to do something else?

I have also structured my objectbox like this:
final vectorStore = ObjectBoxVectorStore(
embeddings: embeddings,
dimensions: 512,
directory: objectBoxDir.path,
macosApplicationGroup: 'group.com.yourcompany.appname',
);

Still nothing seems to be working.

@Shashwat2708
Copy link

#248 (comment)

@vaind this was a fix and not the solution. Did you happen to find a solution for this?

@greenrobot-team
Copy link
Member

@Shashwat2708 Maybe this: the application group value must be 19 characters or shorter. If that is not the issue, please open a new issue with enough information so we can reproduce this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants