Skip to content
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

Is there a way to load a pre-built dynamic library along with flutter-tizen app? #430

Closed
srix55 opened this issue Aug 23, 2022 · 16 comments
Closed
Labels
question Further information is requested

Comments

@srix55
Copy link

srix55 commented Aug 23, 2022

I have built a specific library for linux_ia32, that samsung tv emulators use. I have that lib.so file. No matter where I put it in the tizen folder, my app says it's nowhere to be found. Is there a specific location I need to put the .so file, or is that simply not possible?

@swift-kim
Copy link
Member

Hi. You can create a directory named lib or res under tizen and any file in that directory will be included in your TPK (reference). There are several ways to get a path to the directory at runtime (e.g. using tizen_interop's app_get_resource_path) but the simplest one would be (informal way):

print('${Platform.environment['AUL_ROOT_PATH']}/res');

Then you can use DynamicLibrary.open with the path to open the library.

@swift-kim swift-kim added the question Further information is requested label Aug 23, 2022
@swift-kim
Copy link
Member

Ah, I think you can just pass the lib name only (DynamicLibrary.open('libabc.so')) if you place the library in lib.

@srix55
Copy link
Author

srix55 commented Aug 23, 2022

@swift-kim Thanks a lot. '${Platform.environment['AUL_ROOT_PATH']}lib/mylib.so' - this did it for me. With just the lib name, DynamicLibrary.open isn't finding it for me.

@srix55 srix55 closed this as completed Aug 23, 2022
@srix55
Copy link
Author

srix55 commented Aug 24, 2022

With that, isar works on Tizen 🎈 🥳 Some specific rust steps needed to build the dynamic library. But it works great.

@swift-kim
Copy link
Member

Glad to hear that! I just looked into https://github.com/isar/isar-core/releases and the binary for Android x86 (libisar_android_x86.so) might be used on Tizen emulator as well because it depends on only libc and libdl. I'm not very sure though.

@srix55
Copy link
Author

srix55 commented Aug 25, 2022

Tried using the android x86 binary. Tizen emulator throws up some liblog.so not found on it. Included liblog.so into lib and still it throws the same error.

[E] [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: IsarError: Could not initialize IsarCore library. If you create a Flutter app, make sure to add isar_flutter_libs to your dependencies: Invalid argument(s): Failed to load dynamic library '/opt/usr/apps/signage.player.player/lib/libisar_android_x86.so': liblog.so: cannot open shared object file: No such file or directory

@srix55
Copy link
Author

srix55 commented Aug 25, 2022

Overall, it's awesome that isar works with Tizen. That's huge... Would be awesome if it is in the list of supported tizen plugins. For that, I tried including that prebuilt libisar.so the way isar does - via the isar_flutter_libs package. However my c/c++ skills are non-existent... so tinkering with some cpp code went dud.

For now, it's about including the custom linux_ia32 libisar32.so into tizen build's lib folder and loading it up with '${Platform.environment['AUL_ROOT_PATH']}lib/libisar32.so' for isar. Requires a line of change at isar's end to support linux_ia32 abi.

@swift-kim
Copy link
Member

Hmm, if you don't mind, could you share the binary here? I'd like to do some testing.

@swift-kim
Copy link
Member

It should be possible to let my app load libisar.so before isar loads it if I use isar <= 2.4.0, but the current version of isar (2.5.x and 3.x) doesn't seem to allow it:

https://github.com/isar/isar/blob/2.4.0/packages/isar/lib/src/native/isar_core.dart#L44-L45

https://github.com/isar/isar/blob/3.0.0-dev.12/packages/isar/lib/src/native/isar_core.dart#L210-L213

Which version of isar are you using?

@srix55
Copy link
Author

srix55 commented Aug 25, 2022

I am using isar 2.5.0
Here's the linux_ia32 binary for 2.5.0 -
libisar_linux_ia32.zip

And here, i added a case for linuxIA32

      case Abi.linuxIA32:
        library = 'libisar_linux_ia32.so';
        break;
        
// and later at line 71
if (library == "libisar_linux_ia32.so") 
        _IC ??= IsarCoreBindings(DynamicLibrary.open('${Platform.environment['AUL_ROOT_PATH']}lib/$library'));

@swift-kim
Copy link
Member

I thought the following would work for isar <= 2.4.0 but it didn't.

// Load from path.
DynamicLibrary.open('${Platform.environment['AUL_ROOT_PATH']}/lib/libisar.so');

// Load the same library again by name.
// expected: not throws exception
// actual: throws exception
DynamicLibrary.open('libisar.so');

There doesn't seem to be a way to make things work without modifying the isar code itself. Things will become easier if isar provides something similar to sqlite3's open.overrideFor or open.overrideForAll.

@srix55
Copy link
Author

srix55 commented Aug 26, 2022

The main problem for isar to support 32 bit seems to be that binaries for both x86 & arm64 cannot be shipped in a flutter library as stated by the author here.

Sorry, I don't think it is possible to ship both, x86 and arm64 linux binaries in a Flutter library. You would need to compile Isar core yourself for x86 linux.

@swift-kim
Copy link
Member

The above example code worked by explicitly setting the library's soname to libisar.so by running:

$ patchelf --set-soname libisar.so tizen/lib/libisar.so

but now I see a different error when I click the "Load" button in the quotes sample app. Maybe it's due to a version mismatch or something because I'm using isar 2.4.0 and your binary was built for isar 2.5.0.

Thread 26 "io.flutter.ui" received signal SIGABRT, Aborted.
0xb7784a51 in __kernel_vsyscall ()
(gdb) bt
#0  0xb7784a51 in __kernel_vsyscall ()
#1  0xb75ca246 in __libc_signal_restore_set (set=0x9dafb200) at ../sysdeps/unix/sysv/linux/internal-signals.h:84
#2  __GI_raise (sig=6) at ../sysdeps/unix/sysv/linux/raise.c:48
#3  0xb75b13ce in __GI_abort () at abort.c:79
#4  0xb75b129e in __assert_fail_base (fmt=0xb772c044 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x9e1e4c16 "limit >= 3 - 1", file=0x9e1e415f "mdbx", line=6482,
    function=0x9e1f029c "mdbx_pnl_check") at assert.c:92
#5  0xb75c1de6 in __GI___assert_fail (assertion=0x9e1e4c16 "limit >= 3 - 1", file=0x9e1e415f "mdbx", line=6482, function=0x9e1f029c "mdbx_pnl_check") at assert.c:101
#6  0x9e0bc4f6 in ?? () from target:/opt/usr/globalapps/dev.isar.quotes/lib/libisar.so
#7  0x9e1a641c in ?? () from target:/opt/usr/globalapps/dev.isar.quotes/lib/libisar.so

Anyway we can now make this into a simple Tizen plugin as shown here. lib/isar_flutter_libs_tizen.dart contains code that invokes DynamicLibrary.open and the native part (tizen) only contains the lib/libisar.so binary without actual implementation. You can simply depend on the plugin from your app (it doesn't work in the way isar_flutter_libs does).

But still it will be a problem if I upgrade isar to 2.5.0. You may ask the isar author if we can add just three lines to the package:

      case Abi.linuxArm:
      case Abi.linuxArm64:
      case Abi.linuxIA32:

even though the official libisar.so binary is not available for the architectures.

@swift-kim
Copy link
Member

swift-kim commented Aug 26, 2022

Hmm, it seems you don't even need to call DynamicLibrary.open('${Platform.environment['AUL_ROOT_PATH']}/lib/libisar.so') if the library soname has been set to libisar.so as I mentioned above.

@srix55
Copy link
Author

srix55 commented Aug 27, 2022

That SigAbrt definitely looks like a version mismatch issue. Let me confirm. I'll open a discussion with isar author and see if it can be made possible. Would be awesome to see isar among the list of flutter-tizen supported packages. Will recheck the AUL_ROOT_PATH necessity on my machine. Last time i checked, it couldn't find the binary without it.

@srix55
Copy link
Author

srix55 commented Aug 31, 2022

You are right. There's no need to have AUL_ROOT_PATH when flutter_isar_libs_tizen is included. Some things I verified:

  1. isar_flutter_libs and isar_flutter_libs_tizen can be included in pubspec together for a project and it works fine for web, linux and tizen 6.5 emulator.
  2. Those SigAbrt errors seem to be because of version mismatch. I used 2.5.0 isar version everywhere and did not encounter any errors.
  3. No need for AUL_ROOT_PATH or anything when using the correct libisar.so with isar_flutter_libs_tizen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants