realm/realm-dart

Create an example for compiling and deploying a Dart-only app that uses realm

KhaledBasiony opened this issue · 4 comments

Problem

I don't know how to compile the application as an executable and distribute it.

I have a dart-only server that uses realm,
previously I was on version 1.9.0 and when trying to compile it, it was complaining about the plugin library being accessed outside of flutter (I am sure I was using realm_dart package)

now I upgraded to 3.3.0, hoping that would solve the problem, but now It depends on .dart_tools/package_config.json

Bad state: Could not find package_config.json
#0      _getPackageConfigJson (package:realm_dart/src/handles/native/init.dart:78)
#1      _openRealmLib (package:realm_dart/src/handles/native/init.dart:114)
#2      initRealm (package:realm_dart/src/handles/native/init.dart:157)

I don't know what I am supposed to do now

Solution

I was hoping you could provide a section in the docs or quick start or something to show how to compile/deploy a server or a CLI application step-by-step

Alternatives

No response

How important is this improvement for you?

Dealbreaker

Feature would mainly be used with

Atlas Device Sync

➤ PM Bot commented:

Jira ticket: RDART-1074

@KhaledBasiony Sorry about that - you hit a bug.

We need to find the native shared library for the realm database. One way we do that is to read and parse the .dart_tools/package_config.json file. If you compile your application to an exe file and copy it outside the project directory, it cannot find package_config.json. Obviously this should not fail the process (hence the bug), instead we should try to load the lib from elsewhere.

Since the native assets feature is not stable (yet), you will be required to manually bundle the shared lib with your application. Unlike flutter, we cannot hook into the build process for pure dart.

@nielsenko
Thanks for the reply, I worked around it for now, by providing the shared library file and a dummy .dart_tools/package_config.json + a dummy pubspec.yaml with the release (which is obviously not ideal, but meh)

this is necessary because _openRealmLib calls _getPackageConfigJson Before asking OS to provide the shared library file, so even if the shared library exists in PATH, .dart_tools/package_config.json must still be there too.

@KhaledBasiony You asked for an example, but since you have already made it work (even if it required a work-around, due to #1766, which is being addressed ), we have decided not to do an example for now.

People who use realm with pure dart outside flutter, are few and far apart, and the experience will be much improved once native assets lands.