S
S
Space Around2021-01-24 15:25:07
JavaScript
Space Around, 2021-01-24 15:25:07

How to fix the error: null is not an object (evaluation of 'bleManager.start')?

I use the react-native-ble-manager library to connect an Android phone to a BLE device, but when I call the BleManager.start() method, an error immediately pops up, I tried to look for a solution on GitHub for this library in the Issues section, but nothing helps from proposed, they often write that the library is not installed correctly, I have already double-checked and reinstalled everything 10 times. Here are my installation steps:

  1. npm i --save react-native-ble-manager
  2. // file: android/app/src/main/AndroidManifest.xml
    ...
    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    ...

    Tried to use ACCESS_FINE_LOCATIONboth ACCESS_COARSE_LOCATION, both together and separately.

  3. npm i
  4. It is written in README.md that there is support for autolinking, but I think it will not be superfluous:
    react-native link && react-native link react-native-ble-manager


I don't use Expo. I tried to run the example, but there is the same error, although here is all my code related to this library:
...
import BleManager from 'react-native-ble-manager';
...
const scanAndConnect = () => {
  BleManager.start()    
  .catch((err) => {
    console.error(err);
  });
};

info from build.gradle:
buildToolsVersion = "29.0.2"
minSdkVersion = 16
compileSdkVersion = 29
targetSdkVersion = 29

OS: Android 9.0

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Space Around, 2021-01-24
@viksnamax

The problem was that targetSdkVersionfor Android 9.0 it should be 28 and not 29 in the filebuild.gradle

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question