Is there a solution to handle native errors or crashes without eject Expo? - react-native

I'm novice on React Native development, so I chosed to use Expo.
It seems very convinient, but I can't find a way to handle the case when native error occurs.
I wanted to use 'setNativeExceptionHandler' from "react-native-exception-handler", but I can't use it because it causes "Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable." since it's native package and I can't link it to my project while I'm keeping it under Expo.
So I'm wondering,
Is there any solution or workaround to handle the native error without ejecting Expo?
If there's zero possibility, and if I keep the Expo development environment, what should I do? Is it possible to do like this? "complete everything under Expo -> eject -> insert native error handler -> EAS build" and repeat it every time(modify from the version before eject) when I update the app...?
Or, It's unnecessary because the developers can check the crash info in the App store or Play store?

Related

react native maps stopped working after running expo prebuild

I needed to run the expo prebuild command in my project, due to the need for the notifee notifications library, the library in question worked normally, but the map library that I was also using (react native mps), stopped working. the map simply no longer appears in . does anyone know how to solve?

React Native Error - TypeError: null is not an object (evaluating '_reactNative.NativeModules.RNShare.FACEBOOK')

I'm working on react native project and I am using expo. I want to add the react-native-share package to my project, however I keep getting this error before I even add any code.
TypeError: null is not an object (evaluating '_reactNative.NativeModules.RNShare.FACEBOOK')
Now I know that expo has it's own version of the share, however you can't specify where a person can share it too, which honestly makes the feature useless. It seems to be clear that the reason I can't use this package is because I am using expo and can't install pod into the project -- due to expo reject it --. So what should I do? Any suggestions on how to work around this?
You can't normally use dependencies with native code using Expo. At least when using the classic build system (you're using it when you run expo start in the terminal to run your project). react-native-share has native code (you can check that by going to the repo and seeing if the library has ios and android folders) and therefore can't be used with "standard" Expo.
If you want to use custom native code in your project, you either need to eject from Expo to the bare workflow or - a newer option - use Expo EAS and custom dev clients. Expo EAS allows you to stay in the managed workflow and still use native modules. You might need to write something called a config plugin for some of those native dependencies you want to use, but looking at the documentation, react-native-share should be working just fine without a config plugin.
So: Either eject to the Expo bare workflow, or use Expo EAS and custom dev clients to use native dependencies with the Expo managed workflow. Do note however that you need at least Expo SDK 41 to use EAS and custom development clients.
To learn more about migrating from the classic build system to EAS, see Expo's guide / documentation.

Expo + Stripe CardFormField crashes on Android build

I am implementing Stripe in my React Native (Expo) app. When testing it out with ExpoGO it works well, and so does the iOS build via Testflight. However, after building the app for Android it will crash whenever the CardFormField component (provided by Stripe) is rendered.
I have logged the errors in Sentry, and this is where it goes wrong:
Binary XML file line #5 in [censored]:layout/stripe_card_form_view: Error inflating class com.google.android.material.card.MaterialCardView
IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
I then found this, here:
In order to use CardForm component, you need to install and configure Material Components theme in your app.
I do however fail to find information on how I am expected to comply with this requirement using Expo. Do anyone have any ideas?
I am using:
expo 43.0.3
#stripe/stripe-react-native 0.2.2
App is built with eas
I use expo (not an ejected app)
Thanks in advance for any help.
With Expo you have a choice between managed vs. bare workflows. In order to access the build.gradle and styles.xml files to configure the Material Components theme you need to switch to a bare workflow. You need to use expo eject to create the native Android files in question.

Expo Bare Workflow - How To Use And Setup react-native-pdf and react-native-blob-util - React Native

What is the proper way to use native module in react native expo bare workflow ?
I want to use react-native-pdf and react-native-blob-util
But I got error :
TypeError: null is not an object (evaluating 'ReactNativeBlobUtil.DocumentDir')
And
Invariant Violation: "main" has not been registered. This can happen if:
Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
I have following this link : https://openbase.com/js/react-native-pdf
I read in the expo documentation we can use native module using expo bare workflow. And now my project is bare workflow. In the middle of building my apps using expo bare workflow I got and error when using react-native-pdf and react-native-blob-util
I want when user click the button the apps will open the pdf file which have source link pdf from my server.
Is it possible to setup using this native module in expo bare workflow since bare workflow in the documentation said it like this :
https://docs.expo.dev/introduction/managed-vs-bare/
Bare Workflow
In the bare workflow the developer has complete control, along with
the complexity that comes with that. You can use all packages from the
Expo SDK, development builds, and all Expo and EAS Services.
Configuration with app.json / app.config.js is mostly not supported in
this context; instead, you will need to configure each native project
directly.
Please give me a solution of this problem ? If it is not possible please point me to use another best pdf viewer.
Finally solved the problem.
Native Module cannot run in Expo Go
So expo publish will not working because it is run in Expo Go.
Instead, we must change to run in native. Use case example : npm run android or expo run:android. It will run into bare workflow with native module in our code.
I had this same issue. The fix for me was to rebuild the development client first.
npx expo start --dev-client -c
Then run android/iOS.
There is no need to build with expo run:android.

How to get device Id in expo react native app

I am implementing API to connect app with server. I have to use deviceId there. As mentioned in here we can use third party library 'react-native-device-info'. But when I am using it I am getting errors as attached screenshots. As per error it's saying to do linking but as I am using react version 0.62, so autolinking is there. So What can be issue? It took too much time to search it but till now I didn't get a proper solution.
react-native-device-info library wont work in Expo , since it requires linking of native modules hence the error.It will only work in pure react native apps.
You can check this by expo itself : expo-device
hopeit helps.feel free for doubts
You can use react-native-device-info even in Expo projects. You need to replace Expo Go with a custom build that has react-native-device-info library baked in.
By default, Expo Go used on Android, iPhone Emulators implies managed workflow (aka only expo-* modules are being used). However, using any pure react-native-* libraries falls under bare workflow, so you cannot use Expo Go - the error you see is from Expo Go, not your app.
Build your custom Expo app with expo-dev-client, react-native-device-info libraries included, and install that on your emulators. This needs to be done once when you add a react-native-* library.
Now continue to add code to your project that uses features from react-native-device-info.
npx expo start --dev-client and choose your emulator. Your custom build will be launched and you can make live changes as always like in Expo Go.
Do check out the section on Development Builds from Expo. Needless to say, I have successfully used react-native-device-info on my Expo project, because expo-device cannot provide what I needed.