LtbLightning / bdk-flutter

Bitcoin Development Kit - Flutter Package
MIT License
63 stars 28 forks source link

Failed to load dynamic library 'librust_bdk_ffi.so' #91

Open aniketambore opened 1 year ago

aniketambore commented 1 year ago

I encountered an error while testing the bdk_flutter package on Android. The error message states, "Invalid argument(s): Failed to load dynamic library 'librust_bdk_ffi.so': dlopen failed: library 'librust_bdk_ffi.so' not found."

Here are the details of my environment:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.5, on Microsoft Windows [Version 10.0.22621.1848], locale en-IN)
[✓] Windows Version (Installed version of Windows is version 10 or higher)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Visual Studio - develop for Windows (Visual Studio Community 2022 17.6.4)
[✓] Android Studio (version 2022.2)
[✓] Connected device (3 available)
[✓] Network resources

I also tried to build the package from the source code following the guide provided in the README here to build it from the source code. However, during the execution of the cargo build command, I encountered the following error:

cargo build
   Compiling rust_bdk_ffi v0.28.3 (D:\Flutter My Git Projects\savior_bitcoin_wallet\packages\bdk_flutter\rust)
error: failed to run custom build command for `rust_bdk_ffi v0.28.3 (D:\Flutter My Git Projects\savior_bitcoin_wallet\packages\bdk_flutter\rust)`

Caused by:
  process didn't exit successfully: `D:\Flutter My Git Projects\savior_bitcoin_wallet\packages\bdk_flutter\rust\target\debug\build\rust_bdk_ffi-95e8f8f71007f00d\build-script-build` (exit code: 101)
  --- stdout
  cargo:rerun-if-changed=src/r_api.rs

  --- stderr
  thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: missing pubspec.lock in D:\Flutter My Git Projects\savior_bitcoin_wallet\packages\bdk_flutter\rust\..', build.rs:40:43
  stack backtrace:
     0:     0x7ff769bb0f82 - std::backtrace_rs::backtrace::dbghelp::trace
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\std\src\..\..\backtrace\src\backtrace\dbghelp.rs:98
     1:     0x7ff769bb0f82 - std::backtrace_rs::backtrace::trace_unsynchronized
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
     2:     0x7ff769bb0f82 - std::sys_common::backtrace::_print_fmt
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\std\src\sys_common\backtrace.rs:65
     3:     0x7ff769bb0f82 - std::sys_common::backtrace::_print::impl$0::fmt
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\std\src\sys_common\backtrace.rs:44
     4:     0x7ff769bd415b - core::fmt::write        
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\core\src\fmt\mod.rs:1254
     5:     0x7ff769bac27a - std::io::Write::write_fmt<std::sys::windows::stdio::Stderr>
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\std\src\io\mod.rs:1698
     6:     0x7ff769bb0ccb - std::sys_common::backtrace::_print
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\std\src\sys_common\backtrace.rs:47
     7:     0x7ff769bb0ccb - std::sys_common::backtrace::print
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\std\src\sys_common\backtrace.rs:34
     8:     0x7ff769bb3a6a - std::panicking::default_hook::closure$1
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\std\src\panicking.rs:269
     9:     0x7ff769bb36d0 - std::panicking::default_hook
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\std\src\panicking.rs:288
    10:     0x7ff769bb4146 - std::panicking::rust_panic_with_hook
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\std\src\panicking.rs:691
    11:     0x7ff769bb403e - std::panicking::begin_panic_handler::closure$0
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\std\src\panicking.rs:582
    12:     0x7ff769bb1c29 - std::sys_common::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\std\src\sys_common\backtrace.rs:150
    13:     0x7ff769bb3d50 - std::panicking::begin_panic_handler
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\std\src\panicking.rs:578
    14:     0x7ff769bded75 - core::panicking::panic_fmt
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\core\src\panicking.rs:67
    15:     0x7ff769bdf396 - core::result::unwrap_failed
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\core\src\result.rs:1687
    16:     0x7ff769421650 - core::result::Result<T,E>::unwrap::h64670326139a17f4
    17:     0x7ff769421db4 - std::rt::lang_start::{{closure}}::hac75c70d51e12f73
    18:     0x7ff7694216a6 - core::ops::function::FnOnce::call_once::h65ad1c5d1d9ae976
    19:     0x7ff769422849 - std::sys_common::backtrace::__rust_begin_short_backtrace::h697b787b31b3466d  
    20:     0x7ff76942175c - std::rt::lang_start::{{closure}}::hac75c70d51e12f73
    21:     0x7ff769ba65ce - core::ops::function::impls::impl$2::call_once
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\core\src\ops\function.rs:287
    22:     0x7ff769ba65ce - std::panicking::try::do_call
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\std\src\panicking.rs:485
    23:     0x7ff769ba65ce - std::panicking::try     
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\std\src\panicking.rs:449
    24:     0x7ff769ba65ce - std::panic::catch_unwind
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\std\src\panic.rs:140
    25:     0x7ff769ba65ce - std::rt::lang_start_internal::closure$2
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\std\src\rt.rs:148
    26:     0x7ff769ba65ce - std::panicking::try::do_call
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\std\src\panicking.rs:485
    27:     0x7ff769ba65ce - std::panicking::try     
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\std\src\panicking.rs:449
    28:     0x7ff769ba65ce - std::panic::catch_unwind
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\std\src\panic.rs:140
    29:     0x7ff769ba65ce - std::rt::lang_start_internal
                                 at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library\std\src\rt.rs:148
    30:     0x7ff769421737 - std::rt::lang_start::h5fd06da1e507041c
    31:     0x7ff7694220e9 - main
    32:     0x7ff769bdc40c - invoke_main
                                 at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
    33:     0x7ff769bdc40c - __scrt_common_main_seh  
                                 at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
    34:     0x7ffcbb6e26ad - BaseThreadInitThunk     
    35:     0x7ffcbcb4a9f8 - RtlUserThreadStart    

I also attempted to run the make all command as specified in the guide, but it resulted in the following error:

make all
rustup target add aarch64-apple-ios x86_64-apple-ios
info: component 'rust-std' for target 'aarch64-apple-ios' is up to date
info: component 'rust-std' for target 'x86_64-apple-ios' is up to date
rustup target add aarch64-apple-darwin x86_64-apple-darwin
info: component 'rust-std' for target 'aarch64-apple-darwin' is up to date
info: component 'rust-std' for target 'x86_64-apple-darwin' is up to date
#rustup target add armv7-apple-ios armv7s-apple-ios i386-apple-ios ## deprecated
rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android   
info: component 'rust-std' for target 'aarch64-linux-android' is up to date
info: component 'rust-std' for target 'armv7-linux-androideabi' is up to date
info: component 'rust-std' for target 'i686-linux-android' is up to date
info: component 'rust-std' for target 'x86_64-linux-android' is up to date
cargo install flutter_rust_bridge_codegen
    Updating crates.io index
     Ignored package `flutter_rust_bridge_codegen v1.78.0` is already installed, use --force to override  
cargo install cargo-ndk
    Updating crates.io index
     Ignored package `cargo-ndk v3.2.0` is already installed, use --force to override
cargo lipo --release
[ERROR cargo_lipo] Running on non-macOS, `cargo lipo` will likely not work. Use `--allow-run-on-non-macos` to override this check.
make: *** [makefile:33: target/universal/release/libexample.a] Error 1

I would appreciate any guidance or suggestions on resolving this issue. Thank you!

aniketambore commented 1 year ago

After conducting some search on Stack Overflow related to this issue, I came across this question: https://stackoverflow.com/questions/65551415/failed-to-load-dynamic-library-in-flutter-app

Based on the information provided in the question and the answer, I decided to change my Android emulator API from 31 to 30 and attempted to run the project. Surprisingly, it worked without any issues.

To clarify, the emulator that triggered the error message: "Invalid argument(s): Failed to load dynamic library 'librust_bdk_ffi.so': dlopen failed: library 'librust_bdk_ffi.so' not found." was the Nexus 5x emulator with Release Name S, API Level 31, ABI x86_64, and Target Android 12.0.

On the other hand, the emulator that did not encounter the error was the Nexus 5x emulator with Release Name R, API Level 30, ABI x86, and Target Android 11.0.

Therefore, it seems that this issue is related to a small change in the development environment, specifically the choice of emulator when using bdk_flutter. But yeah, it is worth noting that users utilizing API Level 31 may encounter this error.

BitcoinZavior commented 1 year ago

@aniketambore Not sure what could be wrong, as we have been using bdk-flutter on both API Level 31 and 30. I would suggest creating a new emulator. Will be interesting to know if this turns out to be an issue. The only other issue could be Windows + Android Emulator with API Level 31. Because I have mostly tested on macOS with some testing on Windows and Linux.

brett-doffing commented 1 year ago

Have the same problem with Pixel_3a_API_34_extension_level_7_x86_64 emulator on macOS. Seems to work fine in iOS simulator.

BitcoinZavior commented 1 year ago

@brett-doffing Thanks for your interest. Will check that configuration. Are you targeting Level 7 in particular?

brett-doffing commented 1 year ago

I can't say that I am targeting anything specifically at this point. That is merely the default emulator.

BitcoinZavior commented 1 year ago

Ok, thanks for reporting the issue. Will test on that particular emulator and a few others.

arejula27 commented 9 months ago

I got the same error on linux

Exception has occurred.
ArgumentError (Invalid argument(s): Failed to load dynamic library 'librust_bdk_ffi.so': dlopen failed: library "librust_bdk_ffi.so" not found)

Runing on Pixel_3a_API_34_extension_level_7_x86_64 image

arejula27 commented 9 months ago

I alse used api lvl 30 and 33. Did not worked

bowlarbear commented 8 months ago

I have been encountering the same issue.

When using ADK 11.0 my main thread seems to hang when the wallet is synced (with intermittment crashes). As far as I can tell, this is a known issue https://stackoverflow.com/questions/67755231/flutter-plugin-crash-dump-cpp-failed-to-attach-to-thread-185-permission-denie

When upgrading my device profile to instead use ADK 12.0 I get the error outlined in this issue with the failure to load dynamic library 'librust_bdk_ffi.so'.

Running on Ubuntu 22.04.3 & flutter 3.16.5 Dart 3.2.3, following along with the bdk_flutter_quickstart guide

YannMarti commented 8 months ago

Had the same issue, but it has been resolved with the bdk_flutter: ^0.30.0 version. Unfortunatly that created a new error for me. If you had the error mentioned by op and have the error "'librust_bdk_ffi.so': dlopen failed: cannot locate symbol "__extenddftf2" referenced by" after updating to 0.30.0 you can either use an emulator with api 30 or a real device. If i run it on my phone it works and it has api 33.