react-native-blob-util icon indicating copy to clipboard operation
react-native-blob-util copied to clipboard

TypeError: Cannot read property 'getConstants' of null

Open thiagofgui opened this issue 8 months ago • 8 comments

I'm making an application using expo, and it's showing this error: TypeError: Cannot read property 'getConstants' of null I am using the version "react-native-blob-util": "^0.19.2", i tried running the application on MacOs and Windows and both presented this error, below is a screenshot. imagem_2023-11-01_143827266 imagem_2023-11-01_143938648 Can help me?

thiagofgui avatar Nov 01 '23 17:11 thiagofgui

Have same problem !

massimilianochiodi avatar Nov 20 '23 13:11 massimilianochiodi

+1

Mr-BeanSir avatar Dec 03 '23 15:12 Mr-BeanSir

Same problem for me. It happens immediately with the import, on Android emulator at least. Steps to reproduce:

  1. Create a new expo project (npx create-expo-app testApp)
  2. npm install react-native-blob-util
  3. In App.js, add the line import RNBlobUtil from 'react-native-blob-util';
  4. npx expo start, hit a for Android; fails immediately

I'm on Node 18.18.2

SpencerGreene avatar Dec 10 '23 08:12 SpencerGreene

Same here! Had to remove the dependency from project in order to make it work again ☹️

hugoewarrior avatar Jan 03 '24 20:01 hugoewarrior

Since this lib is using native code, are you all making sure that the native code is included? Depending on what you're doing you might have to use expo prebuilt. This might help you: https://www.sitepen.com/blog/doing-more-with-expo-using-custom-native-code

Which react native version and which react native aritecture are you using? And are you using bridgless mode?

RonRadtke avatar Jan 04 '24 06:01 RonRadtke

I'm going to confess I don't know what most of that means - don't know how to include native code, or expo prebuilt, or bridgless mode.

I can and will look them up - but that said, if you're asking what we're doing to trigger this - in my case it's very simple, just create a new expo project, add the include statement, and invoke on android emulator (as detailed a few comments up).

Are there other step(s) to get it running on Android? It would be great if someone could post a working example.

Since this lib is using native code, are you all making sure that the native code is included?

Depending on what you're doing you might have to use expo prebuilt.

This might help you: https://www.sitepen.com/blog/doing-more-with-expo-using-custom-native-code

Which react native version and which react native aritecture are you using? And are you using bridgless mode?

SpencerGreene avatar Jan 04 '24 07:01 SpencerGreene

I'm going to confess I don't know what most of that means - don't know how to include native code, or expo prebuilt, or bridgless mode.

I can and will look them up - but that said, if you're asking what we're doing to trigger this - in my case it's very simple, just create a new expo project, add the include statement, and invoke on android emulator (as detailed a few comments up).

Are there other step(s) to get it running on Android? It would be great if someone could post a working example.

Since this lib is using native code, are you all making sure that the native code is included? Depending on what you're doing you might have to use expo prebuilt. This might help you: https://www.sitepen.com/blog/doing-more-with-expo-using-custom-native-code Which react native version and which react native aritecture are you using? And are you using bridgless mode?

Assuming you're using newer versions of Expo, then you need to run / build your project a little differently to be able to use this package, or any others that include native code.

tl;dr: you need to use Expo Development Builds

  • still tl;dr: just run your project using npx expo run:android

By default, Expo gets you to run expo start, which will start up the bundler/expo server that bundles up all your project's javascript files. Your test phone / emulator connects to this server to get the latest bundle of javascript files to run.

But what on your phone actually reaches out to get that bundle of javascript and runs it? By default, Expo gets you to download and use the Expo Go app which is a basic app that includes all their default native code / packages, but there's no way to add more native code to that Expo Go app, it can just reach out for the latest javascript.

So instead you can now use development builds, where you generate your own version of the Expo Go app that includes any custom native code or native code from packages.

They push you to use EAS (their cloud service) for building it, but you can do it locally without involving EAS by just running:

npx expo run:android

this will basically build a copy of the expo go app, and install and run it on your emulator / test phone where it will then reach out to the bundler for the js bundle. As part of that process it will generate an android folder locally, but just ignore it. It will be regenerated whenever you run that command or make a new development build.

Technically you should only have to regenerate this development build whenever your native code changes, and just reuse it for grabbing the latest js bundle from your bundler.

m-sterspace avatar Jan 05 '24 16:01 m-sterspace

@m-sterspace thanks for the nice sum-up.

@SpencerGreene As small explanation why you need to do this. React-Native has two (and in detail a few more) parts. There is the javascript part, this is what you mostly build your app in. And there is the native part (which is what actually runs your app), which is usually in java/kotlin or objective-c/swift.

And as @m-sterspace said, expo comes with the native part prebuild to take some (modt of it one time) work off you and give you a nice easy start. But this limits you in using libraries like this one here. I'm using native code to actually be able to download files / save them in the storage etc, or like the getConstants, get the storage paths where files are saved to.

The part about new architecture or not is likely unrelevant for you. But in short, the new or old architecture, and bridgless or not are just different ways on how the javascript code "taks" to the native side. And since this is all farly new in the lib and in react-native there very well code still be bugs.

So in short, just follow the guide above.

RonRadtke avatar Jan 05 '24 17:01 RonRadtke