zo0r / react-native-push-notification

React Native Local and Remote Notifications
MIT License
6.75k stars 2.05k forks source link

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

Closed kindthr closed 1 year ago

kindthr commented 2 years ago

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"
          }
        }
      ]
    ],
github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.