'btleplug' on Android App issue

I am trying to use btleplug on android app but the app is crashing when I am trying to get the first Bluetooth adapter.

let adapters = manager.adapters().await;

I have verified the documents and not sure if this is the issue with jni-utils-rs.

But the build is successful, but the scan function does not work.

Followed these steps for rust android set up.
Building and Deploying a Rust library on Android (mozilla.github.io)

Can you define "crash"?

If it's a panic, you might be able to get a backtrace that'll tell you which line of code (both yours and in btleplug) is encountering the error, which might help figure out the problem. Otherwise, you might be able to attach a debugger and step through yourself.

This is what I observed.

Logs for emulator.

Logs for physical device.

> 2022-12-22 19:48:21.126 15519-15519 libc                    com.example.domain            A  Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 15519 (ware.domain), pid 15519 (ware.domain)
> 2022-12-22 19:48:22.186 15630-15630 DEBUG                   pid-15630                            A  Cmdline: com.example.domain
> 2022-12-22 19:48:22.186 15630-15630 DEBUG                   pid-15630                            A  pid: 15519, tid: 15519, name: ware.domain  >>> com.example.domain <<<
> 2022-12-22 19:48:22.186 15630-15630 DEBUG                   pid-15630                            A        #01 pc 000000000006e510  /data/app/~~uAmwrVwfkFUcCsd8yc0HDg==/com.example.domain-bpEJCzo8rnqI1cO3vrKUqw==/lib/arm64/librust_android.so (std::sys::unix::abort_internal::h7a71b9f8e8a09020+4)
> 2022-12-22 19:48:22.186 15630-15630 DEBUG                   pid-15630                            A        #02 pc 000000000006c504  /data/app/~~uAmwrVwfkFUcCsd8yc0HDg==/com.example.domain-bpEJCzo8rnqI1cO3vrKUqw==/lib/arm64/librust_android.so (rust_panic+132)
> 2022-12-22 19:48:22.186 15630-15630 DEBUG                   pid-15630                            A        #03 pc 000000000006c400  /data/app/~~uAmwrVwfkFUcCsd8yc0HDg==/com.example.domain-bpEJCzo8rnqI1cO3vrKUqw==/lib/arm64/librust_android.so (std::panicking::rust_panic_with_hook::hb800bdf2c3d24185+668)
> 2022-12-22 19:48:22.186 15630-15630 DEBUG                   pid-15630                            A        #04 pc 000000000006c144  /data/app/~~uAmwrVwfkFUcCsd8yc0HDg==/com.example.domain-bpEJCzo8rnqI1cO3vrKUqw==/lib/arm64/librust_android.so (std::panicking::begin_panic_handler::_$u7b$$u7b$closure$u7d$$u7d$::h0716dcb792dd6da4+196)
> 2022-12-22 19:48:22.187 15630-15630 DEBUG                   pid-15630                            A        #05 pc 000000000006aa78  /data/app/~~uAmwrVwfkFUcCsd8yc0HDg==/com.example.domain-bpEJCzo8rnqI1cO3vrKUqw==/lib/arm64/librust_android.so (std::sys_common::backtrace::__rust_end_short_backtrace::h0f111a9c3b1fbc6f+28)
> 2022-12-22 19:48:22.187 15630-15630 DEBUG                   pid-15630                            A        #06 pc 000000000006be88  /data/app/~~uAmwrVwfkFUcCsd8yc0HDg==/com.example.domain-bpEJCzo8rnqI1cO3vrKUqw==/lib/arm64/librust_android.so (rust_begin_unwind+108)
> 2022-12-22 19:48:22.187 15630-15630 DEBUG                   pid-15630                            A        #07 pc 0000000000081084  /data/app/~~uAmwrVwfkFUcCsd8yc0HDg==/com.example.domain-bpEJCzo8rnqI1cO3vrKUqw==/lib/arm64/librust_android.so (core::panicking::panic_fmt::h910640814c8173df+44)
> 2022-12-22 19:48:22.187 15630-15630 DEBUG                   pid-15630                            A        #08 pc 0000000000080fa4  /data/app/~~uAmwrVwfkFUcCsd8yc0HDg==/com.example.domain-bpEJCzo8rnqI1cO3vrKUqw==/lib/arm64/librust_android.so (core::panicking::panic_display::hb393f36cfadfe5ff+52)
> 2022-12-22 19:48:22.187 15630-15630 DEBUG                   pid-15630                            A        #09 pc 0000000000080f68  /data/app/~~uAmwrVwfkFUcCsd8yc0HDg==/com.example.domain-bpEJCzo8rnqI1cO3vrKUqw==/lib/arm64/librust_android.so (core::panicking::panic_str::h7fb39655a9dc50e8+20)
> 2022-12-22 19:48:22.187 15630-15630 DEBUG                   pid-15630                            A        #10 pc 0000000000080d14  /data/app/~~uAmwrVwfkFUcCsd8yc0HDg==/com.example.domain-bpEJCzo8rnqI1cO3vrKUqw==/lib/arm64/librust_android.so (core::option::expect_failed::h1e1953bc5f2a68ba+4)
> 2022-12-22 19:48:22.187 15630-15630 DEBUG                   pid-15630                            A        #11 pc 000000000003bbe8  /data/app/~~uAmwrVwfkFUcCsd8yc0HDg==/com.example.domain-bpEJCzo8rnqI1cO3vrKUqw==/lib/arm64/librust_android.so (_$LT$core..future..from_generator..GenFuture$LT$T$GT$$u20$as$u20$core..future..future..Future$GT$::poll::h2caafad367be8458+268)
> 2022-12-22 19:48:22.187 15630-15630 DEBUG                   pid-15630                            A        #12 pc 000000000003b22c  /data/app/~~uAmwrVwfkFUcCsd8yc0HDg==/com.example.domain-bpEJCzo8rnqI1cO3vrKUqw==/lib/arm64/librust_android.so (_$LT$core..future..from_generator..GenFuture$LT$T$GT$$u20$as$u20$core..future..future..Future$GT$::poll::hc84c01a98a80a9e2+128)
> 2022-12-22 19:48:22.187 15630-15630 DEBUG                   pid-15630                            A        #13 pc 00000000000385e8  /data/app/~~uAmwrVwfkFUcCsd8yc0HDg==/com.example.domain-bpEJCzo8rnqI1cO3vrKUqw==/lib/arm64/librust_android.so (tokio::runtime::park::CachedParkThread::block_on::h00278b116ef3c3db+164)
> 2022-12-22 19:48:22.187 15630-15630 DEBUG                   pid-15630                            A        #14 pc 000000000003a480  /data/app/~~uAmwrVwfkFUcCsd8yc0HDg==/com.example.domain-bpEJCzo8rnqI1cO3vrKUqw==/lib/arm64/librust_android.so (tokio::runtime::runtime::Runtime::block_on::hbbfe37e50fa791bd+128)
> 2022-12-22 19:48:22.187 15630-15630 DEBUG                   pid-15630                            A        #15 pc 00000000000383e0  /data/app/~~uAmwrVwfkFUcCsd8yc0HDg==/com.example.domain-bpEJCzo8rnqI1cO3vrKUqw==/lib/arm64/librust_android.so (rust_core::device::scan::h34896d9e8ec9ef90+120)
> 2022-12-22 19:48:22.187 15630-15630 DEBUG                   pid-15630                            A        #16 pc 0000000000035cc8  /data/app/~~uAmwrVwfkFUcCsd8yc0HDg==/com.example.domain-bpEJCzo8rnqI1cO3vrKUqw==/lib/arm64/librust_android.so (rust_core::core_scan::hd10d918c324116f2+12)
> 2022-12-22 19:48:22.187 15630-15630 DEBUG                   pid-15630                            A        #17 pc 0000000000034a50  /data/app/~~uAmwrVwfkFUcCsd8yc0HDg==/com.example.domain-bpEJCzo8rnqI1cO3vrKUqw==/lib/arm64/librust_android.so (Java_com_example_domain_MainActivity_scan+20)
> 2022-12-22 19:48:22.187 15630-15630 DEBUG                   pid-15630                            A        #20 pc 000000000000067a  [anon:dalvik-classes3.dex extracted in memory from /data/app/~~uAmwrVwfkFUcCsd8yc0HDg==/com.example.domain-bpEJCzo8rnqI1cO3vrKUqw==/base.apk!classes3.dex] (com.example.domain.MainActivity.onCreate$lambda-1+42)
> 2022-12-22 19:48:22.187 15630-15630 DEBUG                   pid-15630                            A        #22 pc 0000000000000588  [anon:dalvik-classes3.dex extracted in memory from /data/app/~~uAmwrVwfkFUcCsd8yc0HDg==/com.example.domain-bpEJCzo8rnqI1cO3vrKUqw==/base.apk!classes3.dex] (com.example.domain.MainActivity.$r8$lambda$PuTAKDKnMHG-ooAzXpXsNIecUB0+0)
> 2022-12-22 19:48:22.187 15630-15630 DEBUG                   pid-15630                            A        #24 pc 0000000000000558  [anon:dalvik-classes3.dex extracted in memory from /data/app/~~uAmwrVwfkFUcCsd8yc0HDg==/com.example.domain-bpEJCzo8rnqI1cO3vrKUqw==/base.apk!classes3.dex] (com.example.domain.MainActivity$$ExternalSyntheticLambda1.onClick+4)
> 2022-12-22 19:48:22.188 15630-15630 DEBUG                   pid-15630                            A        #30 pc 00000000002da2ba  [anon:dalvik-classes.dex extracted in memory from /data/app/~~uAmwrVwfkFUcCsd8yc0HDg==/com.example.domain-bpEJCzo8rnqI1cO3vrKUqw==/base.apk] (com.google.android.material.button.MaterialButton.performClick+22)
> ---------------------------- PROCESS ENDED (15519) for package com.example.domain ----------------------------

Blockquote

Please format the stacktrace as code, it is unreadable like this

Also, can you reproduce the crash without the JNI and maybe even on other operating systems?

The device.rs code works fine on windows. Creating this issue when I am trying to use it for android app.

Finally able to add logs. The issue is while getting the adapter. Checked all the related documents and not able to figure out the issue with adapter.


Followed some additional steps from GitHub - deviceplug/btleplug: Rust Cross-Platform Host-Side Bluetooth LE Access Library and still facing the same issue. Further details updated on below issue.

Android: Fatal signal 6 (SIGABRT) when getting the adapter · Issue #287 · deviceplug/btleplug (github.com)

Will be fixed by using jni 0.19

deviceplug/btleplug#287 (comment)

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.