invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.71k stars 2.22k forks source link

🔥 RNFirebaseBackgroundMessage receives empty NodeModules #3053

Closed aminosman closed 4 years ago

aminosman commented 4 years ago

Issue

I am using RNFirebaseBackgroundMessage to display notifications using firebase.notifications().displayNotification(x) (when app is in background) however all I see is a log message saying You attempted to use a firebase module that's not installed on your Android project by calling firebase.notifications(). I started digging and found that inside initialiseNativeModule. NativeModules is an empty object. I trace this same path when the app is in the foreground and everything works and loads as expected. I am using React Native Navigation so here is the init method of my class.

   AppRegistry.registerHeadlessTask(
        'RNFirebaseBackgroundMessage',
        () => bgMessaging,
  )

  Navigation.events().registerAppLaunchedListener(() => {
       startApp()
  })

I should also note that everything was working prior to up updating to RN 0.61.2 from 0.59.4 and this this library from 4.3.8 to 5.6.0


Project Files

Javascript

Click To Expand

#### `package.json`: ```json "dependencies": { "@ptomasroos/react-native-multi-slider": "^1.0.0", "@react-native-community/async-storage": "^1.6.2", "@react-native-community/blur": "^3.3.1", "@react-native-community/cameraroll": "^1.3.0", "@react-native-community/geolocation": "^2.0.2", "@react-native-community/netinfo": "^4.4.0", "@react-native-community/slider": "^2.0.2", "@react-native-community/viewpager": "^3.2.0", "@yfuks/react-native-action-sheet": "0.0.4", "apollo-boost": "^0.4.4", "apollo-cache-inmemory": "^1.6.3", "apollo-client": "^2.6.4", "apollo-link-context": "^1.0.17", "apollo-link-http": "^1.5.16", "buffer": "^5.1.0", "bugsnag-react-native": "^2.23.2", "circular-json": "^0.5.3", "deprecated-react-native-listview": "0.0.6", "eslint-config-prettier": "^2.9.0", "graphql": "^14.4.2", "graphql-tag": "^2.10.1", "hoist-non-react-statics": "^2.5.0", "lodash": "^4.17.11", "moment": "^2.22.1", "prop-types": "^15.6.1", "qs": "^6.5.2", "react": "16.11.0", "react-apollo": "^3.1.3", "react-native": "0.61.5", "react-native-android-open-settings": "^1.2.0", "react-native-appsflyer": "^1.4.6", "react-native-billing": "^2.10.0", "react-native-branch": "^4.2.1", "react-native-camera": "^3.8.0", "react-native-code-push": "^5.7.0", "react-native-config": "^0.11.7", "react-native-contacts": "^5.0.4", "react-native-datepicker": "^1.7.2", "react-native-deprecated-custom-components": "^0.1.2", "react-native-device-info": "^0.24.3", "react-native-elements": "^0.19.1", "react-native-fast-image": "^7.0.2", "react-native-fbsdk": "^1.0.4", "react-native-firebase": "^5.6.0", "react-native-fs": "^2.14.1", "react-native-geolocation-service": "^3.1.0", "react-native-google-analytics": "^1.3.2", "react-native-haptic-feedback": "^1.8.2", "react-native-iap": "^3.3.9", "react-native-image-crop-picker": "^0.26.0", "react-native-image-picker": "^1.1.0", "react-native-image-progress": "^1.1.1", "react-native-image-resizer": "^1.0.0", "react-native-indicators": "^0.17.0", "react-native-intercom": "^13.2.0", "react-native-keyboard-aware-scroll-view": "^0.9.1", "react-native-keychain": "^3.1.1", "react-native-linear-gradient": "^2.5.6", "react-native-maps": "git+https://git@github.com/react-native-community/react-native-maps.git", "react-native-masonry": "^0.5.0-alpha.5", "react-native-message-compose": "0.0.6", "react-native-modal": "^11.3.1", "react-native-navigation": "4.0.0", "react-native-photo-view": "^1.5.2", "react-native-popup-menu-android": "^1.0.3", "react-native-progress": "^4.0.0", "react-native-recaptcha-v3": "0.0.16", "react-native-segmented-control-tab": "^3.2.2", "react-native-shake": "^3.4.0", "react-native-store-review": "^0.1.5", "react-native-svg": "^9.13.3", "react-native-swipe-list-view": "^2.0.3", "react-native-swipeable": "^0.6.0", "react-native-swipeout": "^2.3.3", "react-native-swiper": "^1.6.0-rc.3", "react-native-tab-navigator": "^0.3.4", "react-native-tab-view": "0.0.77", "react-native-vector-icons": "^4.6.0", "react-native-video": "^5.0.0", "react-native-webview": "^7.4.2", "react-redux": "^7.1.1", "recompose": "^0.30.0", "redux": "^4.0.0", "redux-devtools-extension": "^2.13.8", "redux-persist": "^6.0.0", "redux-persist-filesystem-storage": "^2.0.0", "redux-saga": "^1.1.1", "reselect": "^3.0.1", "rn-fetch-blob": "^0.11.2", "sendbird": "^3.0.108", "warna": "^0.2.4" } ``` ### Android

Click To Expand

#### Have you converted to AndroidX? - [x] my application is an AndroidX application? - [x] I am using `android/gradle.settings` `jetifier=true` for Android compatibility? - [x] I am using the NPM package `jetifier` for react-native compatibility? #### `android/build.gradle`: ```groovy // N/A ``` #### `android/app/build.gradle`: ```groovy implementation ("com.google.firebase:firebase-analytics:17.2.1") implementation ("com.google.firebase:firebase-auth:17.0.0") implementation ("com.google.firebase:firebase-database:19.2.0") implementation ("com.google.firebase:firebase-messaging:20.1.0") implementation ("com.google.firebase:firebase-config:19.1.0") implementation ("com.google.firebase:firebase-core:17.2.1") ``` #### `android/settings.gradle`: ```groovy // N/A ``` #### `MainApplication.java`: ``` package com.minderapps.minder; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.WindowManager; import com.facebook.CallbackManager; import com.facebook.FacebookSdk; import com.facebook.appevents.AppEventsLogger; import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; import com.facebook.soloader.SoLoader; import com.microsoft.codepush.react.CodePush; import com.minderapps.minder.chat.messagelist.ReactMinderPackage; import com.minderapps.minder.toolbar.ReactToolbarPackage; import com.reactnativenavigation.NavigationApplication; import com.reactnativenavigation.react.NavigationReactNativeHost; import com.reactnativenavigation.react.ReactGateway; import java.util.Arrays; import java.util.List; import io.branch.referral.Branch; import io.intercom.android.sdk.Intercom; import io.invertase.firebase.RNFirebasePackage; import io.invertase.firebase.analytics.RNFirebaseAnalyticsPackage; import io.invertase.firebase.auth.RNFirebaseAuthPackage; import io.invertase.firebase.config.RNFirebaseRemoteConfigPackage; import io.invertase.firebase.database.RNFirebaseDatabasePackage; import io.invertase.firebase.messaging.RNFirebaseMessagingPackage; import io.invertase.firebase.notifications.RNFirebaseNotificationsPackage; import android.app.Application; import android.content.Context; import androidx.multidex.MultiDex; import com.facebook.react.PackageList; import java.lang.reflect.InvocationTargetException; public class MainApplication extends NavigationApplication { private static CallbackManager mCallbackManager = CallbackManager.Factory.create(); protected static CallbackManager getCallbackManager() { return mCallbackManager; } private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { @Override public boolean getUseDeveloperSupport() { return BuildConfig.DEBUG; } @Override protected List getPackages() { @SuppressWarnings("UnnecessaryLocalVariable") List packages = new PackageList(this).getPackages(); // Packages that cannot be autolinked yet can be added manually here, for example: // packages.add(new MyReactNativePackage()); return packages; } @Override protected String getJSMainModuleName() { return "index"; } }; @Override public ReactNativeHost getReactNativeHost() { return mReactNativeHost; } @Override protected ReactGateway createReactGateway() { ReactNativeHost host = new NavigationReactNativeHost(this, isDebug(), createAdditionalReactPackages()) { @Override protected String getJSMainModuleName() { return "index"; } @Override public String getJSBundleFile() { return CodePush.getJSBundleFile(); } }; return new ReactGateway(this, isDebug(), host); } @Override protected void attachBaseContext(Context context) { super.attachBaseContext(context); MultiDex.install(this); } @Override public void onCreate() { super.onCreate(); FacebookSdk.sdkInitialize(getApplicationContext()); Branch.getAutoInstance(this); AppEventsLogger.activateApp(this); SoLoader.init(this, false); initializeFlipper(this); // Remove this line if you don't want Flipper enabled if(this.isDebug() || this.isStaging()) { Intercom.initialize(this, getString(R.string.INTERCOM_TEST_API_KEY), getString(R.string.INTERCOM_TEST_APP_ID)); } else { Intercom.initialize(this, getString(R.string.INTERCOM_API_KEY), getString(R.string.INTERCOM_APP_ID)); } registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() { @Override public void onActivityCreated(Activity activity, Bundle savedInstanceState) { activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); } @Override public void onActivityStarted(Activity activity) { } @Override public void onActivityResumed(Activity activity) { } @Override public void onActivityPaused(Activity activity) { } @Override public void onActivityStopped(Activity activity) { } @Override public void onActivitySaveInstanceState(Activity activity, Bundle outState) { } @Override public void onActivityDestroyed(Activity activity) { } }); } @Override public boolean isDebug() { // Make sure you are using BuildConfig from your own application return BuildConfig.DEBUG; } public boolean isStaging() { return BuildConfig.BUILD_TYPE.contentEquals("releaseStaging"); } /** * Loads Flipper in React Native templates. * * @param context */ private static void initializeFlipper(Context context) { if (BuildConfig.DEBUG) { try { /* We use reflection here to pick up the class that initializes Flipper, since Flipper library is not available in release mode */ Class aClass = Class.forName("com.facebook.flipper.ReactNativeFlipper"); aClass.getMethod("initializeFlipper", Context.class).invoke(null, context); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } protected List getPackages() { List packages = new PackageList(this).getPackages(); packages.add(new RNFirebaseAnalyticsPackage()); packages.add(new RNFirebaseAuthPackage()); packages.add(new RNFirebaseDatabasePackage()); packages.add(new RNFirebaseMessagingPackage()); packages.add(new RNFirebaseNotificationsPackage()); packages.add(new RNFirebaseRemoteConfigPackage()); packages.add(new ReactMinderPackage()); packages.add(new ReactToolbarPackage()); return packages; } @Override public List createAdditionalReactPackages() { return getPackages(); } } ``` #### `AndroidManifest.xml`: ``` ```

--- ## Environment
Click To Expand

**`react-native info` output:** ``` System: OS: macOS 10.15.1 CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz Memory: 1.56 GB / 16.00 GB Shell: 5.7.1 - /bin/zsh Binaries: Node: 10.15.1 - /usr/local/bin/node npm: 6.12.0 - ~/.nvm/versions/node/v10.15.1/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1 Android SDK: API Levels: 27, 28, 29 Build Tools: 27.0.3, 28.0.3 System Images: android-24 | Google Play Intel x86 Atom, android-26 | Google Play Intel x86 Atom, android-28 | Google APIs Intel x86 Atom IDEs: Android Studio: 3.4 AI-183.6156.11.34.5522156 Xcode: 11.2.1/11B53 - /usr/bin/xcodebuild npmPackages: react: 16.11.0 => 16.11.0 react-native: 0.61.5 => 0.61.5 npmGlobalPackages: react-native-cli: 2.0.1 ``` - **Platform that you're experiencing the issue on**: - [ ] iOS - [x] Android - [ ] **iOS** but have not tested behavior on Android - [ ] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - `e.g. 5.4.3` - **`Firebase` module(s) you're using that has the issue:** - `e.g. Instance ID` - **Are you using `TypeScript`?** - `Y/N` & `VERSION`

--- Think `react-native-firebase` is great? Please consider supporting all of the project maintainers and contributors by donating via our [Open Collective](https://opencollective.com/react-native-firebase/donate) where all contributors can submit expenses. [[Learn More]](https://invertase.io/oss/react-native-firebase/contributing/donations-expenses) - 👉 Check out [`React Native Firebase`](https://twitter.com/rnfirebase) and [`Invertase`](https://twitter.com/invertaseio) on Twitter for updates on the library.
mikehardy commented 4 years ago

Nothing really stands out for me with regard to your actual problem

I will say as react-native-device-info maintainer you should get current there or you'll have problems on iOS with App Store approval because of UIWebView symbols that are illegal over there now. Unrelated, I know

And a tiny note about versioning for react-native-firebase v5.x.x, you should use a '~' version range now not '^' - as maintainer of v5.x.x I will put breaking changes into minor version bumps in order to track underlying SDKs without running into the RNFBv6 versioning space. Also unrelated, I know.

I'm currently stumped on the real problem in this one, sorry.

stale[bot] commented 4 years ago

Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?

This issue will be closed in 15 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.