0

Im total noob in RN and Expo. I'v generated new project expo init test, then cd test, then npm install --save react-native-ble-plx and started expo by npm start.
In my code I added following lines:

import { BleManager } from 'react-native-ble-plx';
export const manager = new BleManager();
manager.onStateChange(onStateChange);

When Im trying to run it from ios emulator/android or web Im getting error:

Native module cannot be null.

So, is it possible to run native module like react-native-ble-plx in Expo? If yes what am I doing wrong?

Andrei V
  • 1,468
  • 3
  • 17
  • 32

1 Answers1

3

You need to eject your expo project to be able to use this library.

Source

Mohaimin
  • 664
  • 4
  • 10
  • Thank you. And after Ejecting can I still run it from Expo or do i need to run each ios/android using XCode or ADS? – Andrei V Aug 08 '21 at 17:07
  • Don't think you can, after ejecting you handle each OS platform builds yourself. More info on the setup: https://reactnative.dev/docs/environment-setup – Mohaimin Aug 08 '21 at 17:20
  • oh. Then whats the point of RN if one external library throws you off? – Andrei V Aug 08 '21 at 17:23
  • Expo is for prototyping and very easy to start and experiment with. Expo built apps are huge too. But if you want to build a serious/production app, it's best and recommended to use the native cli to do that. There you will have all the access you need to low level APIs and a lot more customization – Mohaimin Aug 08 '21 at 17:30
  • Sorry Im confused :) but whole appealing point of RN is develop in JS and then its ported into native codes. Then why bother with RN if I have to develop in native codes (swift and Java)? – Andrei V Aug 08 '21 at 17:34
  • Mohaimin, just to clarify. After Ejecting app I have continue development in Swift and Java OR I can still develop in JS but when I deploy my apps I have to do it from native codes? Thank you again. – Andrei V Aug 08 '21 at 17:53
  • Oh, haha, no, you wont have to code in Swift or Java(You can but you need to in 99% cases). It's just that you'd have more control over the libraries and build process of the app when you eject. You can read up on the link I posted earlier on Ejecting. – Mohaimin Aug 08 '21 at 18:06
  • @AndreiV do not confuse Expo with RN. You can eject the project from Expo and continue to use RN (JS or TypeScript) wihtout needing to get into the native codebase. However, you will loose many of the managed features Expo CLI provides and you'll pretty much have to manually build and run your RN project. – bombillazo Oct 18 '21 at 20:15