Problem after linking Firebase to a React Native app - android

I am trying to link my react-native app to firebase and work on the auth module.
I followed the steps of the installation in https://rnfirebase.io/
It works when I run npx react-native run-android
But when I use expo start to work on the pre-production app I always get the error you attempted to use a firebase module that is not installed firebase.app()

After working on this problem for while, after solving it, I would like to share my answer.
The library https://rnfirebase.io/ does not work with a managed workflow like Expo, so be sure to use the bare workflow to work with the library.

Related

Problem initializing project in ReactNative CLI

My name is fernando and I'm studying mobile development via React Native
I'm having trouble using the React Native CLI, as I couldn't solve this problem I decided to do all the steps from the recommended https://reactnative.dev/docs/environment-setup again to run the code.
I uninstalled Java, node, Android Studio, JDK and gradle.
I installed Java, Node and Java using Chocolatey as recommended by the documentation, I strictly performed all the steps requested but I cannot install the application on the simulator or on the cell phone via USB
Starts NPM START normally without errors.
But when starting NPM RUN ANDROID it gives me the following error
enter image description here
OBS:
The project in question in the image, has no code, it was only opened using npx react-native init AwesomeProject
Another observation that I can run and program using React native EXPO GO
It works without errors and I can run both in the simulator and in USB
Thank you and I would appreciate it if someone could help me

react-native-google-mobile-ads with Expo managed workflow will not work

I have followed all of the most up-to-date guides and suggestions for getting react-native-google-mobile-ads to work with an Expo managed workflow, including these:
How to use react-native-google-mobile-ads with Expo?
How do I use react-native-google-mobile-ads with Expo and Expo Go?
But I keep getting the same error:
ERROR TypeError: null is not an object (evaluating 'RNAppModule.eventsNotifyReady')
It would seem that this error originates in this jest.setup.ts file:
https://github.com/invertase/react-native-google-mobile-ads/blob/main/jest.setup.ts
but I have no idea what the error is or how to overcome it.
This error happens when I initiate interstitial.load() as per the official documentation.
Any help would be greatly appreciated.
Ran into this same problem. Turns out the command to use was hidden in their docs at the end of the build steps without any explanation.
https://docs.page/invertase/react-native-google-mobile-ads#setting-up-google-admob
Using react-native-google-mobile-ads, Expo Go will no longer be able to handle linking all the native dependencies. So you'll have to use EAS to build it. Per the docs, you can use npx eas-cli build --profile development to build for development. Alternatively, to install locally rather than on EAS servers, add the --local flag to that command. Just note that if building locally you may need to set the Android SDK path following the instructions to edit your eas.json at Expo build EAS - local - SDK location not found.
After building for Android (I don't have a Mac so I can't speak for development on iOS), it generates an apk which you need to install on your device. I'm sure there's a way to install this on an emulator too.
Once you've opened that app, it will direct you to start a development server using expo start --dev-client. This will run a dev server similar to the usual Expo Go. It pulls up a QR code which you can scan and it will take you into your app. Hot reload works as expected too. Doing this my test banner ad showed up without any errors.
The same solution is discussed here.

React Navigation (using Expo) - location of the MainActivity.java file?

I am going through the React Navigation documentation.
In the React Navgation - Getting Started instructions, it says that
"To finalise installation of react-native-gesture-handler for Android", I need to edit the MainActivity.java file.
However I don't have that file in my project, or any other similar directory pertaining to it (./android).
I created my project using expo-cli, in particular:
# To create a new React Native project
$ expo init project-name
# And to run the App in Expo
$ expo start
I am wondering if I have to create a build and how is it done, in order for Expo to create the files used by Android and iOS builds, or is there something else that I'm missing?
Expo
As you used Expo to create your app you will not have an android folder as these are abstracted away from you.
If you wish to use a dependency that requires you to edit native code then you need to eject your application. https://docs.expo.io/versions/latest/expokit/eject
From your command line run expo eject and it will build the necessary ios and android folders for you. However there are several ramifications if you eject your app. You should read the above link carefully.
react-navigation
However, as Expo recommend using react-navigation you don't need to install the react-native-gesture-handler as it is already installed in Expo
https://reactnavigation.org/blog/2018/11/17/react-navigation-3.0.html#installation
First, install the library using your favorite package manager:
yarn add react-navigation#^3.0.0
Next, install react-native-gesture-handler. If you’re using Expo you don’t need to do anything here, it’s included in the SDK.
It even mentions it on the installation instructions page https://reactnavigation.org/docs/en/getting-started.html#installation
Next, install react-native-gesture-handler. If you’re using Expo you
don’t need to do anything here, it’s included in the SDK. Otherwise:
react-native-gesture-handler
Similarly checking the documentation for react-native-gesture-handler it says:
Gesture Handler is already part of Expo and there is no extra
configuration required. However, consider that the Expo SDK team may
take some time to include the newest version of the library - so Expo
might not always support all our latest features as soon as they are
out.
https://kmagiera.github.io/react-native-gesture-handler/docs/getting-started.html#with-expo-https-expoio
Creating a build with Expo
There is no point repeating the steps here to create a build with Expo it goes into quite some detail in the Expo documentation which can be found here https://docs.expo.io/versions/latest/distribution/building-standalone-apps

watchPosition fails with react native expo

Hi I'm beginner in React Native, and I used react-native-create-app to generate a react native app.
I'm using navigator.geolocation.watchPosition(...) in it
Exactly as in the example here https://facebook.github.io/react-native/releases/0.24/docs/geolocation.html
(I ejected in order to add geolocation permission in AndroidManifest.xml as described)
When I npm start, and scan the QR code given by Expo, I have the following error
error screenshot
However, when I'm running the app with react-native run-android instead, it's working well.
But I would like to continue to use Expo, somebody had already encounter this issue or someone see a way to solve it ? Thanks !

Integrating react-native to an existing android app?

I have been trying out React-Native for a while . It would be really helpful if I could build parts of my app using react-native.
Yes, you can use react-native in your existing android-app. Read through the "Extensibility" section of this page, it explains (quite clearly) how it can be done.

Categories

Resources