Cannot create new BleManager in React Native app using Expo with react-native-ble-plx

515 Views Asked by At

Can't Create New BleManager.

hello guys,

I'm making a React Native app to control an ESP32 device using the react-native-ble-plx library. I have cloned and modified the BLESampleExpo example project, and I added a welcome screen when the user opens the application after that I can click on "get started", to go to the project screen: Welcome Screen.

the app works fine on the welcome page. However, when I go to the other screen, I get the following error: The Error Message From Expo.

Render Error: Cannot read property 'createClient' of null

I have tried commenting out parts of the code to know from where the issue, and I think the problem is coming from this line of code:

const bleManager = useMemo(() => new BleManager(), []);

Can anyone please help me solve this error?

I have found a lot of Stack Overflow questions about the same problem, but none of them have solved it. Is the react-native-ble-plx library still working? If not, what other library should I use?

1

There are 1 best solutions below

0
Tang Yetong On

I got the same error, and fixed it after following the config plugin react-native-ble-plx installation guide from this blog and running the development server instead of Expo Go.

To summarize:

  1. After adding this config in the app.config.js or app.json file:
    ...
    "plugins": [
      [
        "@config-plugins/react-native-ble-plx",
        {
          "isBackgroundEnabled": true,
          "modes": [
            "peripheral",
            "central"
          ],
          "bluetoothAlwaysPermission": "Allow $(PRODUCT_NAME) to connect to bluetooth devices"
        }
      ]
    ],
    ...
  1. Run expo prebuild
  2. Create a development build npx eas build --profile development
  3. Scan the QR code, install the app on your phone and run it
  4. Finally yarn start --dev-client, and the development server should pop up on your phone, select and run it