ble
ble copied to clipboard
Issue running the Bluetooth plugin inside my worker
I'm running into issues with my svelte-native application when I try to instantiate the Bluetooth from the plugin inside my Worker.
I've created a demo project so I could more easily reproduce the issue (https://github.com/AdrianoOP/bluetooth-worker-test). I can make it work perfectly in the main thread, but in the Worker I an error when trying to instantiate the Bluetooth class. Before trying to instantiate the class I'm making sure that permissions have been granted.
Situation happens both with my simulator (Android 13) and cellphone (Android 11)
const communicator = new Bluetooth(); // throws the error below
Error: Trying to link invalid 'this' to a Java object Error: Trying to link invalid 'this' to a Java object
at new ScanCallBackImpl (file: app/webpack:/bluetooth-worker-test/node_modules/@nativescript-community/ble/index.android.js:466:0)
at new Bluetooth (file: app/webpack:/bluetooth-worker-test/node_modules/@nativescript-community/ble/index.android.js:1004:0)
at handleScanMessage (file: app/webpack:/bluetooth-worker-test/app/bluetooth-worker.ts:25:23)
at globalThis.onmessage (file: app/webpack:/bluetooth-worker-test/app/bluetooth-worker.ts:10:18)
At the moment I suspect the issue is somewhere inside this function: https://github.com/nativescript-community/ble/blob/4c4d55ebdad4fe1ef117a4dbbbd0f8c7eb7ca405/src/ble/index.android.ts#L539
My package.json files: package.json package-lock.json
@AdrianoOP thanks for opening an issue. will help tracking it. I am sorry I did not have time to look at it. will br able to so it next week. would that br good with you ?
@farfromrefug no worries. I thought could a good idea to open the issue, maybe someone has already seen it.
Sure, whenever you can... I'll keep studying it.
@farfromrefug as we were discussing in the discord community, it seems it is an issue related to the android package.
There is a PR opened for that, but while it is not merged an work around can be using the build related to the PR (https://github.com/NativeScript/android/actions/runs/7234213102). You just need to unzip and add it replacing the content inside /platform/android