shekohex / flutterust

Flutter + Rust = :heart:
Apache License 2.0
699 stars 56 forks source link

Failed to load dynamic library #16

Closed yiv closed 3 years ago

yiv commented 3 years ago

Android 5.1.1 ( API level 22)

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.

shekohex commented 3 years ago

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).

yiv commented 3 years ago

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"]