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.64k stars 2.21k forks source link

RNFBMessagingModule.getToken got 4 arguments, expected 2 error #6287

Closed wilav-dev closed 2 years ago

wilav-dev commented 2 years ago

Issue

After upgrading from 14.9.4 to 14.11.0, I'm getting this error in Android, RN 0.67.4:

WhatsApp Image 2022-06-05 at 9 45 07 AM

I run watchman delete, cleared react native cache and still happening

try {
  let fcmToken = await messaging().getToken();
  if (fcmToken) {
      config.headers['fcm-token'] = fcmToken;
  }
} catch (err) {
  console.error(err);
}

Javascript

Click To Expand

#### `package.json`: ```json "@react-native-firebase/analytics": "^14.11.0", "@react-native-firebase/app": "^14.11.0", "@react-native-firebase/crashlytics": "^14.11.0", "@react-native-firebase/dynamic-links": "^14.11.0", "@react-native-firebase/messaging": "^14.11.0", ``` #### `firebase.json` for react-native-firebase v6: ```json { "react-native": { "crashlytics_debug_enabled": false } } ```

Android

Click To Expand

#### `android/build.gradle`: ```groovy dependencies { classpath 'com.android.tools.build:gradle:4.2.2' classpath 'com.google.gms:google-services:4.3.10' classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.0' classpath 'com.google.firebase:perf-plugin:1.4.1' } ``` #### `android/app/build.gradle`: ```groovy apply plugin: 'com.android.application' apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.firebase.crashlytics' apply plugin: 'com.google.firebase.firebase-perf' release { // Caution! In production, you need to generate your own keystore file. // see https://reactnative.dev/docs/signed-apk-android. signingConfig signingConfigs.debug minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" firebaseCrashlytics { nativeSymbolUploadEnabled true unstrippedNativeLibsDir 'build/intermediates/merged_native_libs/release/out/lib' } } ``` #### `android/settings.gradle`: ```groovy rootProject.name = 'MERN' include ':react-native-signature-capture' project(':react-native-signature-capture').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-signature-capture/android') include ':react-native-image-picker' project(':react-native-image-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-image-picker/android') include ':@react-native-community_datetimepicker' project(':@react-native-community_datetimepicker').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/datetimepicker/android') include ':react-native-vector-icons' project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android') include ':react-native-gesture-handler' project(':react-native-gesture-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gesture-handler/android') apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) include ':app' ```


Environment

Click To Expand

- **Platform that you're experiencing the issue on**: - [ ] iOS - [x] Android - [ ] **iOS** but have not tested behavior on Android - [x] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native` version you're using that has this issue:** - 0.67.4 - **`react-native-firebase` version you're using that has this issue:** - 14.11.0

mikehardy commented 2 years ago

You must have a mismatch between your javascript bundle and your native code. The native code parameter list was widened to 4 so it appears you have the native code and a stale bundle This type of error has been diagnosed for others as code push dropping a bundle on you unexpectedly with old javascript code from the module, and also as stale build artifacts cached incorrectly (e.g., you need npx react-native-clean-project to clear them out)

Either way, this is definitely not a problem with the module itself, it's a local project javascript / native version mismatch that needs local diagnosis, and if it were happening here then this test would not pass:

https://github.com/invertase/react-native-firebase/blob/ee740f80501fdd2ea5184515c4840340fca55e63/packages/messaging/e2e/messaging.e2e.js#L150-L158

... so I'm going to close this as inactionable though I hope you find your root cause quickly and can get moving again

nguyenhoanglam commented 2 years ago

@wilav-dev Have you solve your issue? If you fix it successfully, please help me with this issue!

mikehardy commented 2 years ago

@nguyenhoanglam if you see an error about "got N arguments, expected Y arguments" it is always always always (repeat a few more time (always) a mismatch between your javascript bundle versions and your native code versions.

FIrst make sure you have the native code versions you expect (in package.json and then built to the device), and use npx react-native-clean-project to make sure things are clean.

Then make sure you don't have codepush or Expo OTA updates turned on and dropping an old bundle into the app after launch that doesn't match.

That should get things working with matching code.

nguyenhoanglam commented 2 years ago

@mikehardy Using npx react-native-clean-project does not solve the issue. The app works in debug mode but crashes when running release APK file. I find that if I downgrade com.android.tools.build:gradle version from 7.1.x to 7.0.2, the issue will be solved! I hope you would inspect why the lib does not work with gradle 7.1.x.

mikehardy commented 2 years ago

That's going to be a react native compatibility issue. You can't go over Gradle plugin 7.0 until react native 69 if I recall

Bamorem commented 2 years ago

Well for me, i got this issue only on some devices. for example on mine it's working but on the device of my college got this issue. So i guess using npx react-native-clean-project is only a temporary solution. what if i release the app on the market and random people will have they app crashing without knowing why...

mikehardy commented 2 years ago

@Bamorem that sounds a lot like bundles are out of date because of over-the-updates like expo-ota or react-native-codepush. I can't think of another way for the native code + javascript bundle to skew like that such that it works sometimes or does not work other times.

memon07 commented 1 year ago

@mikehardy any updates on this issue ? i tried using npx react-native-clean-project and as mentioned by @nguyenhoanglam it doesnt work on relase build . I tried downgrading the gradle version but it still didn't worked ( react-native v : 0.71.1, build gradle : 7.3.1, gradle v : 7.5.1)

memon07 commented 1 year ago

Update : release build is now getting generated ; i had to remove react native flipper entirely from the project

i have updated an answer on stackoverflow

GordonOnGithub commented 11 months ago

In my case, the root cause of this issue is that the React version of the React Native project is not aligned with that of the React web app contained by the native app. The issue is fixed after updating React to 18 on both sides.