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

I am trying to use sqlx for sqlite through rust frb v2 #1719

Closed
debojyoti452 opened this issue Feb 3, 2024 · 15 comments
Closed

I am trying to use sqlx for sqlite through rust frb v2 #1719

debojyoti452 opened this issue Feb 3, 2024 · 15 comments
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@debojyoti452
Copy link

Describe the bug

I am trying to use sqlx for sqlite through rust frb v2 but getting this error on android run. Building is working fine.

E/flutter ( 9868): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument(s): Failed to load dynamic library 'librust_lib.so': dlopen failed: cannot locate symbol "__extenddftf2" referenced by "/data/app/~~4t8ZBCcFskEbsMOKdY79Ag==/com.swing.hexagon.hexagon_flutter-OI2Iz7v_OHZHUI6KqbGHuw==/lib/x86_64/librust_lib.so"...
E/flutter ( 9868): #0      _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:11:43)
E/flutter ( 9868): #1      new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:22:12)
E/flutter ( 9868): #2      new ExternalLibrary.open (package:flutter_rust_bridge/src/platform_types/_io.dart:39:47)
E/flutter ( 9868): #3      loadExternalLibraryRaw (package:flutter_rust_bridge/src/loader/_io.dart:56:28)
E/flutter ( 9868): #4      loadExternalLibrary (package:flutter_rust_bridge/src/loader/_io.dart:14:10)
E/flutter ( 9868): #5      BaseEntrypoint._loadDefaultExternalLibrary (package:flutter_rust_bridge/src/main_components/entrypoint.dart:107:13)
E/flutter ( 9868): #6      BaseEntrypoint.initImpl (package:flutter_rust_bridge/src/main_components/entrypoint.dart:53:31)
E/flutter ( 9868): #7      RustLib.init (package:hexagon_flutter/generated_rust/frb_generated.dart:26:20)
E/flutter ( 9868): #8      main (package:hexagon_flutter/main.dart:44:17)
E/flutter ( 9868): #9      _runMain.<anonymous closure> (dart:ui/hooks.dart:301:23)
E/flutter ( 9868): #10     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
E/flutter ( 9868): #11     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
E/flutter ( 9868): 

Steps to reproduce

Hint: A simple way to reproduce is to clone and modify the https://github.com/fzyzcjy/flutter_rust_bridge/tree/master/frb_example/dart_minimal example package according to your needs.

  1. ...
  2. ...
  3. ...

Logs

E/flutter ( 9868): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument(s): Failed to load dynamic library 'librust_lib.so': dlopen failed: cannot locate symbol "__extenddftf2" referenced by "/data/app/~~4t8ZBCcFskEbsMOKdY79Ag==/com.swing.hexagon.hexagon_flutter-OI2Iz7v_OHZHUI6KqbGHuw==/lib/x86_64/librust_lib.so"...
E/flutter ( 9868): #0      _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:11:43)
E/flutter ( 9868): #1      new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:22:12)
E/flutter ( 9868): #2      new ExternalLibrary.open (package:flutter_rust_bridge/src/platform_types/_io.dart:39:47)
E/flutter ( 9868): #3      loadExternalLibraryRaw (package:flutter_rust_bridge/src/loader/_io.dart:56:28)
E/flutter ( 9868): #4      loadExternalLibrary (package:flutter_rust_bridge/src/loader/_io.dart:14:10)
E/flutter ( 9868): #5      BaseEntrypoint._loadDefaultExternalLibrary (package:flutter_rust_bridge/src/main_components/entrypoint.dart:107:13)
E/flutter ( 9868): #6      BaseEntrypoint.initImpl (package:flutter_rust_bridge/src/main_components/entrypoint.dart:53:31)
E/flutter ( 9868): #7      RustLib.init (package:hexagon_flutter/generated_rust/frb_generated.dart:26:20)
E/flutter ( 9868): #8      main (package:hexagon_flutter/main.dart:44:17)
E/flutter ( 9868): #9      _runMain.<anonymous closure> (dart:ui/hooks.dart:301:23)
E/flutter ( 9868): #10     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
E/flutter ( 9868): #11     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
E/flutter ( 9868):

Expected behavior

No response

Generated binding code

No response

OS

No response

Version of flutter_rust_bridge_codegen

No response

Flutter info

No response

Version of clang++

No response

Additional context

No response

@debojyoti452 debojyoti452 added the bug Something isn't working label Feb 3, 2024
@fzyzcjy fzyzcjy added the awaiting Waiting for responses, PR, further discussions, upstream release, etc label Feb 3, 2024
@fzyzcjy
Copy link
Owner

fzyzcjy commented Feb 3, 2024

dlopen failed: cannot locate symbol "__extenddftf2" referenced by "/data/app/~~4t8ZBCcFskEbsMOKdY79Ag==/com.swing.hexagon.hexagon_flutter-OI2Iz7v_OHZHUI6KqbGHuw==/lib/x86_64/librust_lib.so"

Looks like this symbol is not found, thus this may not be a bug of flutter_rust_bridge, but related to how the Rust code is copiled. One reason may be that, sqlx/sqlite needs some special configurations in order to be used on android.

@debojyoti452
Copy link
Author

dlopen failed: cannot locate symbol "__extenddftf2" referenced by "/data/app/~~4t8ZBCcFskEbsMOKdY79Ag==/com.swing.hexagon.hexagon_flutter-OI2Iz7v_OHZHUI6KqbGHuw==/lib/x86_64/librust_lib.so"

Looks like this symbol is not found, thus this may not be a bug of flutter_rust_bridge, but related to how the Rust code is copiled. One reason may be that, sqlx/sqlite needs some special configurations in order to be used on android.

Yeah, it is working on real device, but not on emulator.

@fzyzcjy fzyzcjy added bug Something isn't working and removed bug Something isn't working labels Feb 4, 2024
@fzyzcjy
Copy link
Owner

fzyzcjy commented Feb 4, 2024

Aha, then is it possible because sqlx/sqlite does not have things like precompiled binaries for x86/x64?

@debojyoti452
Copy link
Author

yeah exactly, trying to figure out whether there is any other way around. btw tried rusqlite, that too didn't worked on emulator.

@fzyzcjy
Copy link
Owner

fzyzcjy commented Feb 4, 2024

Then one way may be to ask in wrapper libs like sqlx, e.g. I guess maybe they will add x64 files.

@debojyoti452
Copy link
Author

@gridbox
Copy link

gridbox commented Feb 5, 2024

@debojyoti452 How do you have your project configured? I am currently using sqlcipher with sqlx via FRB. I had to configure libsqlite3-sys in my Cargo.toml to use the bundled version of sqlcipher but you should be able to do the same with the vanilla sqlite. I have been able to run on MacOS, Android Emulator, and iOS Simulator.

Here's a snippet from my Cargo.toml

libsqlite3-sys = { version = "*", features = [
    "bundled-sqlcipher-vendored-openssl",
] }
sqlx = { version = "0.7", features = [
    "sqlite",
    "runtime-tokio",
    "macros",
    "uuid",
    "chrono",
] }

@debojyoti452
Copy link
Author

Thanks @gridbox for the suggestion. I am currently shifted to rusqlite. But not working on android emulator. Working fine on real device though. And working fine all other platforms too.
Let try with libsqlite3 🙏

@debojyoti452
Copy link
Author

@fzyzcjy btw is there any way we can set NDK version?

@debojyoti452
Copy link
Author

x86 emulator working fine, but not at all able to make it work on x86_x64 emulator 😢

@fzyzcjy
Copy link
Owner

fzyzcjy commented Feb 8, 2024

btw is there any way we can set NDK version?

Since flutter_rust_bridge is using cargokit for the default template (assuming you are using the default template), I guess cargokit may have some options to configure that.

@debojyoti452
Copy link
Author

btw is there any way we can set NDK version?

Since flutter_rust_bridge is using cargokit for the default template (assuming you are using the default template), I guess cargokit may have some options to configure that.

@fzyzcjy trying to find it in cargokit

@mike-lloyd03
Copy link

mike-lloyd03 commented Feb 27, 2024

I had a problem getting sqlite projects to build for Android using uniffi. This comment pointed me in the right direction. This is what my build.rs looks like for that project to solve this problem:

use std::env;

fn main() {
    let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
    let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();

    if target_arch == "x86_64" && target_os == "android" {
        let android_home = env::var("ANDROID_HOME").expect("ANDROID_HOME not set");
        const ANDROID_NDK_VERSION: &str = "26.1.10909125";
        const LINUX_X86_64_LIB_DIR: &str =
            "toolchains/llvm/prebuilt/linux-x86_64/lib/clang/17/lib/linux/";
        println!("cargo:rustc-link-search={android_home}/ndk/{ANDROID_NDK_VERSION}/{LINUX_X86_64_LIB_DIR}");
        println!("cargo:rustc-link-lib=static=clang_rt.builtins-x86_64-android");
    }
}

Modified from this build.rs.

Note that I haven't tried this with frb yet so this might not work as is.

Copy link

stale bot commented Apr 29, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Apr 29, 2024
@stale stale bot closed this as completed May 8, 2024
Copy link
Contributor

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 22, 2024
@fzyzcjy fzyzcjy removed the awaiting Waiting for responses, PR, further discussions, upstream release, etc label Jun 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants