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

running builder_runner fails with object box inside a package #486

Closed w461 closed 1 year ago

w461 commented 1 year ago

I have separated the data (and domain) layer to packages underneath my project. Now if I take your User example (by the way, it should end with } not )), I am able to run build_runner with an entity file in the project root lib. However, if I place the same file in the lib of the package, and run build_runner from the data package directory, I receive the following error: [SEVERE] objectbox_generator:generator on lib/$lib$: ` FormatException: Unexpected end of input (at character 1) ^ [INFO] Running build completed, took 3.9s [INFO] Caching finalized dependency graph completed, took 529ms [SEVERE] Failed after 4.5s`

The dependencies are added to the data package yaml and I also see libobjectbox.dylib inside the lib directory of the data package from running bash.

greenrobot-team commented 1 year ago

Thanks for reporting! Can you share a minimal example of how your directory structure looks like so we can reproduce this?

The error message looks like the generator does not get any input.

Also fixed the typo in the docs.

Edit: double posted on Stack Overflow.

w461 commented 1 year ago

is tjhis sufficient?

myProject myProject/lib myProject/lib/pubspec.yaml myProject/packages/lib/objectbox-datamodel.dart myProject/packages/lib/libobjectbox.g.dart myProject/packages/lib/pubspec.yaml

w461 commented 1 year ago

pubspec.yaml

name: cleaningfairy_data
description: Data Sources for the Cleaning Fairy
version: 0.0.1

environment:
  sdk: '>=2.18.4 <3.0.0'
  flutter: ">=1.17.0"

dependencies:
  cleaningfairy_domain:
    path: ../domain
  equatable: ^2.0.5
  dartz: ^0.10.1
  uuid: ^3.0.6
  objectbox: ^1.6.2
  objectbox_flutter_libs: any

dev_dependencies:
  build_runner: ^2.3.2
  build_web_compilers: ^3.0.0
  json_serializable: ^6.3.1
  test: ^1.21.4
  mockito: ^5.3.0
  objectbox_generator: any

flutter:
  assets:
    - assets/
w461 commented 1 year ago

Apologies, I did this too quickly while boarding the airplane... The structure should be (I added the data package)

myProject myProject/lib myProject/lib/pubspec.yaml myProject/packages/data/lib/objectbox-datamodel.dart myProject/packages/data/lib/libobjectbox.g.dart myProject/packages/data/lib/pubspec.yaml

I am running build_runner from the directory myProject/packages/data

greenrobot-team commented 1 year ago

Thanks! ObjectBox expects the recommended package structure. In your case pubspec.yaml should exist above the lib folder. If that's not it, I'll have to recreate your setup.

myProject
myProject/pubspec.yaml
myProject/lib
myProject/packages/data/pubspec.yaml
myProject/packages/data/lib/objectbox-datamodel.dart
myProject/packages/data/lib/libobjectbox.g.dart
w461 commented 1 year ago

Sorry for the inconvenience - another "typo". You are right, and my pubspec.yaml is (was) located at data/pubspec.yaml. So it must be something else

w461 commented 1 year ago

can you reproduce the issue?

greenrobot-team commented 1 year ago

I tried with a sub-package that is Dart only and one containing a Flutter dependency. Both work using dart run build_runner build and flutter pub run build_runner build respectively.

I remember seeing this error before, but I can't find anything related.

w461 commented 1 year ago

So sorry for wasting your efforts. I was using flutter pub run build_runner build instead of dart run build_runner build for my dart package. I had some other error initially and I guess with moving files to the parent flutter app, I always re-ran the flutter build command without thinking also for the dart package.

Now I receive the following [WARNING] objectbox_generator:generator on lib/$lib$: Failed to find package root from output directory, generated imports might be incorrect. [WARNING] No actions completed for 25.6s, waiting on:

Is there a different way than running the app to check if everything is fine?

greenrobot-team commented 1 year ago

The Failed to find package root from output directory, generated imports might be incorrect. warning appears to be incorrectly printed if the output directory is the package source root directory (e.g. lib). This will be fixed in an upcoming release.

However, at least in my test the generator still works fine.

greenrobot-team commented 1 year ago

1.7.0 is out which not longer prints the incorrect warning. It also prints the detected paths if it will detect an incorrect out path.

Use flutter pub upgrade or dart pub upgrade to update.

@w461 Let us know if you continue having issues.

w461 commented 1 year ago

Thanks Uwe. Issues stopped as soon as I did everything properly - works like a charm (for now)