objectbox / objectbox-dart

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

Could not prepare directory: objectbox (30) #130

Closed aarajput closed 2 years ago

aarajput commented 3 years ago

I am getting below error when i try to call Store(getObjectBoxModel());

Screen Shot 2020-10-14 at 11 37 44 AM
aarajput commented 3 years ago

This is my pubspec.yaml

name: App
description: Flutter application to show app to users.

publish_to: 'none'

version: 1.0.2+3

environment:
  sdk: ">=2.9.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter

  cupertino_icons: ^1.0.0
  built_value: ^7.1.0
  built_collection: ^4.3.2
  wc_form_validators: ^0.1.1
  cached_network_image: ^2.3.1
  after_layout: ^1.0.7+2
  dio: ^3.0.10
  intl: ^0.16.1
  bloc: ^6.0.3
  flutter_bloc: ^6.0.6
  hydrated_bloc: ^6.0.1
  animations: ^1.1.2
  page_transition: ^1.1.6
  flutter_i18n: ^0.20.0
  flutter_translate_annotations: ^1.0.0
  dotted_border: ^1.0.6
  package_info: ^0.4.3
  device_info: ^0.4.2+8
  shimmer: ^1.1.1
  timeago: ^2.0.27
  flutter_facebook_auth: ^0.3.2
  wc_flutter_share: ^0.2.2
  url_launcher: ^5.7.2
  youtube_player_flutter: ^7.0.0+7
  flutter_svg: ^0.19.0
  flutter_html:
    git: https://github.com/aarajput/flutter_html.git
  webview_flutter: ^1.0.0
  shared_preferences: ^0.5.12
  random_string: ^2.1.0
  sign_in_with_apple: ^2.5.2
  google_sign_in: ^4.5.4
  file_picker: ^2.0.7
  image_crop: ^0.3.3
  objectbox: ^0.8.0
  objectbox_flutter_libs: ^0.8.0

dev_dependencies:
  flutter_test:
    sdk: flutter
  built_value_generator: ^7.1.0
  flutter_translate_gen: ^1.2.1
  objectbox_generator: ^0.8.0
  build_runner: ^1.10.3

dependency_overrides:
  analyzer: 0.40.4

flutter:
  uses-material-design: true
aarajput commented 3 years ago

This is output of my flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.22.1, on Mac OS X 10.15.6 19G2021, locale en-US)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 12.0.1)
[✓] Android Studio (version 4.0)
[!] IntelliJ IDEA Ultimate Edition (version 2019.3)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[!] VS Code (version 1.43.2)
    ✗ Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[✓] Connected device (1 available)
greenrobot commented 3 years ago

The important info "hides" as an error code (30). You seem to be using a read-only directory.

cett01 commented 3 years ago

I am facing this problem in ios. Any solution?

aarajput commented 3 years ago

I solved this issue by passing directory to store constructor.

cett01 commented 3 years ago

I solved this issue by passing directory to store constructor.

var store = Store(getObjectBoxModel(), directory: "ordinap"); It didn't solve problem. Actually problem is that: ObjectBoxException: failed to create store: 10199 Could not prepare directory (permission denied):

How to solve the ios permission problem for storage read and write?

aarajput commented 3 years ago

No, use path provider and get application directory

greenrobot-team commented 3 years ago

The Flutter example uses code like this:

    getApplicationDocumentsDirectory().then((dir) {
      _store = Store(getObjectBoxModel(), directory: dir.path + "/objectbox");
    });

See also the examples README about Flutter and https://github.com/objectbox/objectbox-dart/blob/main/example/flutter/objectbox_demo/lib/main.dart

vaind commented 3 years ago

Considering Flutter is currently the most common platform, we should probably update that example README to and move the flutter variant to be the first one? What do you think @greenrobot-team

greenrobot-team commented 3 years ago

Yes. However, it always confused me that how to annotate and do basic setup is in the examples README and not the main README. And the main README has setup instructions and usage examples. Any reason why this can't all be in the main README?

vaind commented 3 years ago

Yes. However, it always confused me that how to annotate and do basic setup is in the examples README and not the main README. And the main README has setup instructions and usage examples. Any reason why this can't all be in the main README?

This is done to improve the listing on pub.dev: example/README.md shows up in the Example tab.

I agree it can be improved though, but let's address that in a new issue: #135

greenrobot-team commented 3 years ago

Pivoting: research if it's possible to let ObjectBox auto-detect Flutter (e.g. reflective access to Flutter APIs) and always choose an appropriate default directory. Or put differently: make Store(getObjectBoxModel()) work regardless if Dart or Flutter.

greenrobot-team commented 3 years ago

There is official unstable (https://api.dart.dev/stable/2.10.2/dart-mirrors/dart-mirrors-library.html) and third-party limited support for reflection (https://github.com/google/reflectable.dart/blob/master/reflectable/README.md). Official is unstable and not supported by Flutter (https://github.com/flutter/flutter/issues/1150), third-party requires annotating classes to reflect on. So both won't help in this case.

Maybe use the code generator somehow?