shekohex / flutterust

Flutter + Rust = :heart:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Failed to load dynamic library

yiv opened this issue · comments

commented
  • Device

Android 5.1.1 ( API level 22)

  • Error log
E/flutter ( 9499): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: Invalid argument(s): Failed to load dynamic library (dlopen failed: empty/missing DT_HASH in "libsearch_ffi.so" (built with --hash-style=gnu?))
E/flutter ( 9499): #0      _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:11:55)
E/flutter ( 9499): #1      new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:20:12)
  • Upgrade notes from Android

GNU hashes (Availible in API level >= 23)
The GNU hash style available with --hash-style=gnu allows faster symbol lookup and is now supported by the dynamic linker in API 23 and above. (Use --hash-style=both if you want to build code that uses this feature >= Android M but still works on older releases.)

DT_GNU_HASH is availible in API level >= 23, before that only DT_HASH was been supported. And the output of Rust set the default symbol lookup hash style to GNU_HASH which unsupported on old device of API level 22 and below. Some topics recommand set --hash-style=both, I have been trying hard to find how to do this with cargo.

the --hash-style option is not related to Cargo specifically .. nor Rust .. it something related to the linker you are using in most cases I guess it is ld so what I suggest is adding .cargo/config.toml file to your code (in the root of the project) with options to customize/add linker options.
in this case, you need to add --hash-style=both option in android targets.

something like this code should work:

[target.aarch64-linux-android]
rustflags = ["-C", "link-arg=--hash-style=both"]

[target.x86_64-linux-android]
rustflags = ["-C", "link-arg=--hash-style=both"]

not test :D

feel free to add more targets if it worked (but yeah you got the idea).

commented

Thanks a lot, after adding lines like below,
Error of empty/missing DT_HASH has been fixed.

[target.aarch64-linux-android]
rustflags = ["-C", "link-arg=-Wl,--hash-style=both"]

[target.armv7-linux-androideabi]
rustflags = ["-C", "link-arg=-Wl,--hash-style=both"]

[target.i686-linux-android]
rustflags = ["-C", "link-arg=-Wl,--hash-style=both"]

[target.x86_64-linux-android]
rustflags = ["-C", "link-arg=-Wl,--hash-style=both"]