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

Android: Fatal signal 6 (SIGABRT) when getting the adapter #287

Closed
Avani-A-S opened this issue Dec 26, 2022 · 13 comments
Closed

Android: Fatal signal 6 (SIGABRT) when getting the adapter #287

Avani-A-S opened this issue Dec 26, 2022 · 13 comments
Assignees
Labels
android Issues related to the android core bug Something isn't working

Comments

@Avani-A-S
Copy link

Describe the bug
For Android platform, getting this error while getting the adapter.
Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 16382 (rustapplication), pid 16382 (rustapplication)

    let manager = Manager::new().await.unwrap();

    log::info!("get the first bluetooth adapter");
    // get the first bluetooth adapter
    let adapters = manager.adapters().await?;

Taking the code reference from https://docs.rs/btleplug/0.10.4/btleplug/. This work fine on windows. When trying to cross compile for android, creating SIGABRT error.

Provided more details https://users.rust-lang.org/t/btleplug-on-android-app-issue/86339.

@Avani-A-S Avani-A-S added the bug Something isn't working label Dec 26, 2022
@qwandor qwandor added the android Issues related to the android core label Dec 26, 2022
@qdot
Copy link
Contributor

qdot commented Dec 26, 2022

How are you building the android system? Did you build and bring in the droidplug classes from btleplug too? I'm wondering if this is a missing java symbol or something.

@Avani-A-S
Copy link
Author

I have followed steps in this blog. I created the app with same steps and then added the btleplug too.
https://blog.devgenius.io/integrating-rust-with-android-development-ef341c2f9cca

This is my Cargo.toml file.
image

@qdot
Copy link
Contributor

qdot commented Dec 27, 2022

That blog has nothing to do with our project. Did you follow the extra steps outlined in our README? https://github.com/deviceplug/btleplug#android

@Avani-A-S
Copy link
Author

First, I started implementation as per README only. Faced same error for adapter so I googled some more and found devgenius blog. Let me try again as per README and I'll share the issue with code.

@Avani-A-S
Copy link
Author

Will you be able to list out set up steps in detail. Not sure how to build java portion of btleplug or jni-util-rs and how to connect it with my android app from the steps.

I am new with rust and android both. For local set up I need to checkout both this and add to my project?
https://github.com/deviceplug/jni-utils-rs, classcache branch
https://github.com/deviceplug/btleplug, android-tokio branch

@Avani-A-S
Copy link
Author

Added the base code here. You might look into it provide some pointers.
https://github.com/Avani-A-S/bledemoapp

@Avani-A-S
Copy link
Author

@qdot Followed these steps as per README and yet facing same issue. Pushed latest changes here https://github.com/Avani-A-S/bledemoapp.

Steps followed:

  1. Checked out jni-utils-rs and btleplug locally.
  2. Opened jni-utils-rs in Android Studio and build libs at path "jni-utils-rs\target\debug\java\libs" with following commands.

$ cargo build
$ cd java
$ ./gradlew build

  1. Opened btleplug/src/droidplug/java in Android Studio. Updated build.gradle for above generated lib dependencies.

dependencies {
compile fileTree(dir: '/jni-utils-rs/target/debug/java/libs', include: ['*.jar'])
}

  1. Build -> Rebuild Project. AAR generated at 'btleplug\src\droidplug\java\build\outputs\aar\droidplug-debug.aar'

  2. Placed above generated .aar at my android app location 'android\app\libs'

  3. Added .aar file dependencies in build.gradle.
    image

  4. Run the app, clicked on scan button and still facing same error when trying to get the adapter.
    image

@Oppzippy
Copy link

Oppzippy commented Jan 3, 2023

I was getting Fatal signal 6 (SIGABRT) as well, and in my case it, turned out to be not calling btleplug::platform::init (panic was here I think: https://github.com/deviceplug/btleplug/blob/master/src/droidplug/mod.rs#L20). Building with debug symbols made it easy to find.

I don't think btleplug::platform::init is mentioned anywhere in the readme or docs, so that should probably be added.

@Avani-A-S
Copy link
Author

Your issue resolved with btleplug::platform::init? Can you tell me where to use it.

@Oppzippy
Copy link

Oppzippy commented Jan 3, 2023

It's a little outdated but see the code snippet here #8 (comment). It doesn't really matter where you put it, it just needs to be called before you do anything with btleplug. So putting it in an init function that you call manually like this is fine too.

@Avani-A-S
Copy link
Author

Yes. I tried that but facing error expected struct jni::wrapper::jnienv::JNIEnv, found struct JNIEnv.
image

Facing the same issue with flutter as well so reported trobanga/flutter_btleplug#4.

Not sure if this is the issue related to versions of libraries I am using -
jni-utils - 0.1.0
btleplug - 0.10.4
jni - 0.20.0

@Oppzippy
Copy link

Oppzippy commented Jan 4, 2023

jni should be 0.19.0

@Avani-A-S
Copy link
Author

@Oppzippy Thanks a lot! It finally worked with jni 0.19.0 and by adding btleplug::platform::init.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Issues related to the android core bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants