objectbox / objectbox-dart

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

Flutter Linux deployments broken because of missing library #504

Closed HankG closed 1 year ago

HankG commented 1 year ago

I'm experimenting with doing manual deployments of an app on many platforms including Linux. On the Linux platform the app won't start because it can't find the libobjectbox.so library. Looking at the executable with ldd it looks like the link is being set to a link one directly up from the bundle directory to build/linux/x64/release/_deps/... rather than within the build/linux/x64/release/bundle/libs folder. Ironically the file libobjectbox_flutter_libs_plugin.so is in that proper location so it is only the base library that causes the problem.

Basic info (please complete the following information):

  1. Create a flutter project with the library
  2. Build the project on a Linux machine with the command flutter build linux --release
  3. Copy the corresponding build bundle directory to a non-build machine
  4. Attempt to run the executable

Expected behavior

The program runs without the need for manually copying libraries, setting LD_LIBRARY_PATH etc.

greenrobot-team commented 1 year ago

See the Dart tab at https://docs.objectbox.io/getting-started, specifically the part about "Deploying Dart-native projects".

If that doesn't answer your question, please follow up!

HankG commented 1 year ago

See the Dart tab at https://docs.objectbox.io/getting-started, specifically the part about "Deploying Dart-native projects".

If that doesn't answer your question, please follow up!

This is a Flutter app not a Dart native app. This problem doesn't exist on Mac or Windows just on Linux. It seems on those platforms the build script is correctly placing the objectbox library in the same location as the objectbox flutter libs plugin library. I think that should probably be what happens on Linux as well. Then when the app is linked it looks for it in the nested directory instead of elsewhere on the build system and it "just works" on the end user's machine.

greenrobot-team commented 1 year ago

Sorry, I quickly jumped to Dart native because as you said with Flutter the library is bundled automatically.

I could reproduce this on Ubuntu 22.04 using the relations example. The output of ldd objectbox_demo_relations indeed has the following (after moving the bundle folder into ~/Downloads/obx_demo):

libobjectbox_flutter_libs_plugin.so => /home/<user>/Downloads/obx_demo/./lib/libobjectbox_flutter_libs_plugin.so 
libflutter_linux_gtk.so => /home/<user>/Downloads/obx_demo/./lib/libflutter_linux_gtk.so
libobjectbox.so => /home/<user>/git/objectbox-dart/objectbox/example/flutter/objectbox_demo_relations/build/linux/x64/release/_deps/objectbox-download-src/lib/libobjectbox.so

It appears libobjectbox.so is treated as a globally installed library. Will have to check if flutter_libs/linux/CMakeLists.txt (same for sync_flutter_libs) needs to be updated.

greenrobot-team commented 1 year ago

@HankG I've just released preview version 1.7.2-dev.0 which should resolve this issue by no longer linking the shared library into the built executable. Let me know if this resolves the issue for you as well.

(Note: using flutter pub upgrade will not update to this preview version, manually change the version in your pubspec.yaml instead and run flutter pub get.)

HankG commented 1 year ago

I've confirmed that this is working now. Awesome! Thanks!

greenrobot-team commented 1 year ago

@HankG Thanks!

The fix is now available in the latest stable version 1.7.2.