react-native-push-notification icon indicating copy to clipboard operation
react-native-push-notification copied to clipboard

@react-native-firebase_app' could not be found in project

Open kindthr opened this issue 3 years ago • 0 comments

In my React Native 0.68.2 app i'm trying to use react-native-firebase and i have done everything except react-native-link as it's not supported in the latest version of React Native. When I run my project, it shows error from the node module of react-native-firebase. I'm guessing it's happening for some version conflict. Here is the long error :

Error: You attempted to use a firebase module that's not installed on your Android project by calling firebase.app().

Ensure you have:

  1. imported the 'io.invertase.firebase.app.ReactNativeFirebaseAppPackage' module in your 'MainApplication.java' file.

  2. Added the 'new ReactNativeFirebaseAppPackage()' line inside of the RN 'getPackages()' method list.

See http://invertase.link/android for full setup instructions.

Here's my app build/gradle file dependencies:

classpath('com.android.tools.build:gradle:7.0.4') classpath('com.facebook.react:react-native-gradle-plugin') classpath('de.undercouch:gradle-download-task:4.1.2') classpath 'com.google.gms:google-services:4.3.13'

And my android/app/build/gradle :

apply plugin: "com.android.application" apply plugin: 'com.google.gms.google-services'

implementation "com.facebook.react:react-native:+"  // From node_modules
implementation project(path: ":@react-native-firebase_messaging")
implementation project(path: ":@react-native-firebase_app")

And setting.gradle :

include ':@react-native-firebase_messaging' project(':@react-native-firebase_messaging').projectDir = new File(rootProject.projectDir, './../node_modules/@react-native-firebase/messaging/android')

include ':@react-native-firebase_app' project(':@react-native-firebase_app').projectDir = new File(rootProject.projectDir, './../node_modules/@react-native-firebase/app/android')

And MainApplication :

import io.invertase.firebase.messaging.ReactNativeFirebaseMessagingPackage; packages.add(new ReactNativeFirebaseMessagingPackage());

App.js :

import messaging from '@react-native-firebase/messaging';
messaging().setBackgroundMessageHandler(async remoteMessage => {
  console.log("Message handled in the background!", remoteMessage);
})

const unsub = messaging().onMessage(async remoteMessage=>{
  Alert.alert('A new FCM msg arrived', JSON.stringify(remoteMessage))
  console.log(remoteMessage);
  return unsub;
})

app.json :

"plugins": [
      "@react-native-firebase/app",
      "@react-native-firebase/crashlytics",
      
      [
        "expo-build-properties",
        {
          "ios": {
            "useFrameworks": "static"
          }
        }
      ]
    ],


kindthr avatar Aug 16 '22 11:08 kindthr