innoveit / react-native-ble-manager

React Native BLE communication module
http://innoveit.github.io/react-native-ble-manager/
Apache License 2.0
2.11k stars 756 forks source link

Cannot read property 'start' of null in Expo #1257

Closed medero closed 2 weeks ago

medero commented 2 weeks ago

Describe the bug When initiating BleManager.start I get 'cannot read property 'start' of null in Expo 51 / React Native 0.74.5 and thus unable to get permissions and scan devices (my goal is connecting to an Aranet4 device)

Implementation here: https://github.com/medero/react-native-ble-manager-expo-example/blob/main/app/(tabs)/index.tsx

To Reproduce Steps to reproduce the behavior:

  1. Clone this repository: https://github.com/medero/react-native-ble-manager-expo-example
  2. yarn & yarn run android
  3. Scan the QR code (in my case, Galaxy S22) using this development mode (is this the same as using EOS?)
  4. Experience the error "Cannot read property 'start' of null"

Expected behavior Expectation is to not receive that error in order to establish bluetooth permissions and scan for devices.

Screenshots Screenshot_20240910_124004_Expo Go

Smartphone (please complete the following information):

marcosinigaglia commented 2 weeks ago

You have to use a development build https://docs.expo.dev/develop/development-builds/create-a-build/

medero commented 2 weeks ago

You have to use a development build https://docs.expo.dev/develop/development-builds/create-a-build/

Thanks - I think I was confused because I could've sworn I tried a development build (with one of the.. 3-4 build commands - there are a few aliases) and it didn't work but will try a proper eos build. Any tips on speeding up eos builds?

medero commented 2 weeks ago

You have to use a development build https://docs.expo.dev/develop/development-builds/create-a-build/

I updated the repo after making an EOS build and installing the app on my Phone and still no dice..

INFO never_ask_again INFO never_ask_again INFO never_ask_again INFO request android 31 INFO never_ask_again INFO never_ask_again INFO never_ask_again WARN Bluetooth permissions not granted.

Note: In my repo I nullified app.json's eas.projectId. It initially asked me for Location and I believe I granted it but now those default to never_ask_again.

Screenshot of the app:

Screenshot_20240910_144647_react-native-ble-manager-expo-example

medero commented 2 weeks ago

I actually ended up getting this easily to work with react-native-ble-plx which had app.json with permissions set in android.permissions, tried to emulate it and no dice still. Even tried removing my initial call to requestPermissions on HomeScreen load and just am calling it on the Scan button Press incase Android sees that as "spammy" of requesting permissions and defaults it to a no.

Working react-native-ble-plx https://github.com/medero/react-native-ble-plx-example - it also uses the @config-plugins/react-native-ble-plx which seems like it could be the trick to why this works:

    "@config-plugins/react-native-ble-plx",
    {
      "isBackgroundEnabled": true,
      "modes": [
        "peripheral",
        "central"
      ],
      "bluetoothAlwaysPermission": "Allow $(PRODUCT_NAME) to connect to bluetooth devices"

Would be curious to see if I missed anything with ble-manager here.

medero commented 2 weeks ago

This is probably why https://blog.theodo.com/2023/07/ble-integration-for-rn-apps/ mentions it doesn't have support for Expo

marcosinigaglia commented 2 weeks ago

@medero the example in the repo use expo.