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

Versions mismatch in release mode only (You've attempted to require '@react-native-firebase/messaging' version '6.3.4', however, the '@react-native-firebase/app' module is of a different version (6.4.0)) #3396

Closed 404-html closed 4 years ago

404-html commented 4 years ago

Issue

Happens only in release mode (dev works fine). App crashes right after opening. Clearing npm cache made no difference. Running react-native-clean-project clean-project-auto made no difference. I'm getting the same results if I build through AppCenter or on my machine. Following got logged in Google Play:

com.facebook.react.common.JavascriptException: Error: You've attempted to require '@react-native-firebase/messaging' version '6.3.4', however, the '@react-native-firebase/app' module is of a different version (6.4.0). All React Native Firebase modules must be of the same version. Please ensure they match up in your package.json file and re-run yarn/npm install., js engine: hermes, stack: anonymous@1:530314 anonymous@1:833492 v@1:25872 d@1:25565 o@1:25191 anonymous@1:691202 v@1:25872 d@1:25565 o@1:25191 anonymous@1:690101 v@1:25872 d@1:25565 o@1:25191 anonymous@1:683153 v@1:25872 d@1:25565 o@1:25191 anonymous@1:492833 v@1:25872 d@1:25565 o@1:25191 anonymous@1:491589 v@1:25872 d@1:25565 o@1:25191 anonymous@1:489738 v@1:25872 d@1:25565 o@1:25191 anonymous@1:32359 v@1:25872 d@1:25522 o@1:25191 global@1:24923 at com.facebook.react.modules.core.ExceptionsManagerModule.reportException(ExceptionsManagerModule.java at java.lang.reflect.Method.invoke (Native Method) at com.facebook.react.bridge.JavaMethodWrapper.invoke (JavaMethodWrapper.java:372) at com.facebook.react.bridge.JavaModuleWrapper.invoke (JavaModuleWrapper.java:151) at com.facebook.react.bridge.queue.NativeRunnable.run (Native Method) at android.os.Handler.handleCallback (Handler.java:883) at android.os.Handler.dispatchMessage (Handler.java:100) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage (MessageQueueThreadHandler.java:27) at android.os.Looper.loop (Looper.java:214) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run (MessageQueueThreadImpl.java:226) at java.lang.Thread.run (Thread.java:919)


Project Files

Javascript

Click To Expand

#### `package.json`: ```json { "name": "...", "version": "0.0.1", "private": true, "scripts": { ... }, "dependencies": { "@react-native-community/google-signin": "^3.0.3", "@react-native-community/image-editor": "^2.2.0", "@react-native-community/netinfo": "^5.3.3", "@react-native-firebase/admob": "^6.4.0", "@react-native-firebase/analytics": "^6.4.0", "@react-native-firebase/app": "^6.4.0", "@react-native-firebase/auth": "^6.4.0", "@react-native-firebase/messaging": "^6.4.0", "@react-native-firebase/remote-config": "^6.4.0", "axios": "^0.19.2", "lodash": "^4.17.15", "parse": "^2.11.0", "react": "16.11.0", "react-native": "0.62.1", "react-native-animatable": "^1.3.3", "react-native-camera": "^3.19.0", "react-native-code-push": "^6.2.0", "react-native-device-info": "^5.5.3", "react-native-exception-handler": "^2.10.8", "react-native-fbsdk": "^1.1.1", "react-native-iap": "^4.4.2", "react-native-image-zoom-viewer": "^2.2.27", "react-native-restart": "^0.0.13", "react-native-snowflakes": "^1.0.2", "react-native-ux-cam": "^5.1.15", "react-native-video": "^5.0.2", "react-redux": "^7.2.0", "redux": "^4.0.5", "redux-logger": "^3.0.6", "redux-thunk": "^2.3.0" }, "devDependencies": { "@babel/core": "7.7.2", "@babel/runtime": "7.7.2", "@react-native-community/eslint-config": "0.0.5", "babel-jest": "24.9.0", "eslint": "6.6.0", "jest": "24.9.0", "metro-react-native-babel-preset": "^0.58.0", "react-test-renderer": "16.11.0" }, "jest": { "preset": "react-native" } } ``` #### `firebase.json` for react-native-firebase v6: ```json { "react-native": { "admob_android_app_id": "..." } } ```

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby # N/A ``` #### `AppDelegate.m`: ```objc // N/A ```


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? - [ ] I am using the NPM package `jetifier` for react-native compatibility? - [x] I am using Hermes? #### `android/build.gradle`: ```groovy // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { buildToolsVersion = "28.0.3" minSdkVersion = 16 compileSdkVersion = 28 targetSdkVersion = 28 googlePlayServicesAuthVersion = "16.0.1" // added for react-native-iap, https://github.com/dooboolab/react-native-iap#getting-started androidXAnnotation = "1.1.0" androidXBrowser = "1.0.0" } repositories { google() jcenter() } dependencies { classpath("com.android.tools.build:gradle:3.5.2") classpath 'com.google.gms:google-services:4.3.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { mavenLocal() maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url("$rootDir/../node_modules/react-native/android") } maven { // Android JSC is installed from npm url("$rootDir/../node_modules/jsc-android/dist") } google() jcenter() maven { url 'https://www.jitpack.io' } maven { url "http://sdk.uxcam.com/android/" } } } ``` #### `android/app/build.gradle`: ```groovy apply plugin: "com.android.application" import com.android.build.OutputFile /** * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets * and bundleReleaseJsAndAssets). * These basically call `react-native bundle` with the correct arguments during the Android build * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the * bundle directly from the development server. Below you can see all the possible configurations * and their defaults. If you decide to add a configuration block, make sure to add it before the * `apply from: "../../node_modules/react-native/react.gradle"` line. * * project.ext.react = [ * // the name of the generated asset file containing your JS bundle * bundleAssetName: "index.android.bundle", * * // the entry file for bundle generation. If none specified and * // "index.android.js" exists, it will be used. Otherwise "index.js" is * // default. Can be overridden with ENTRY_FILE environment variable. * entryFile: "index.android.js", * * // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format * bundleCommand: "ram-bundle", * * // whether to bundle JS and assets in debug mode * bundleInDebug: false, * * // whether to bundle JS and assets in release mode * bundleInRelease: true, * * // whether to bundle JS and assets in another build variant (if configured). * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants * // The configuration property can be in the following formats * // 'bundleIn${productFlavor}${buildType}' * // 'bundleIn${buildType}' * // bundleInFreeDebug: true, * // bundleInPaidRelease: true, * // bundleInBeta: true, * * // whether to disable dev mode in custom build variants (by default only disabled in release) * // for example: to disable dev mode in the staging build type (if configured) * devDisabledInStaging: true, * // The configuration property can be in the following formats * // 'devDisabledIn${productFlavor}${buildType}' * // 'devDisabledIn${buildType}' * * // the root of your project, i.e. where "package.json" lives * root: "../../", * * // where to put the JS bundle asset in debug mode * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", * * // where to put the JS bundle asset in release mode * jsBundleDirRelease: "$buildDir/intermediates/assets/release", * * // where to put drawable resources / React Native assets, e.g. the ones you use via * // require('./image.png')), in debug mode * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", * * // where to put drawable resources / React Native assets, e.g. the ones you use via * // require('./image.png')), in release mode * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", * * // by default the gradle tasks are skipped if none of the JS files or assets change; this means * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to * // date; if you have any other folders that you want to ignore for performance reasons (gradle * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ * // for example, you might want to remove it from here. * inputExcludes: ["android/**", "ios/**"], * * // override which node gets called and with what additional arguments * nodeExecutableAndArgs: ["node"], * * // supply additional arguments to the packager * extraPackagerArgs: [] * ] */ project.ext.react = [ enableHermes: true, // clean and rebuild if changing ] apply from: "../../node_modules/react-native/react.gradle" apply from: "../../node_modules/react-native-code-push/android/codepush.gradle" /** * Set this to true to create two separate APKs instead of one: * - An APK that only works on ARM devices * - An APK that only works on x86 devices * The advantage is the size of the APK is reduced by about 4MB. * Upload all the APKs to the Play Store and people will download * the correct one based on the CPU architecture of their device. */ def enableSeparateBuildPerCPUArchitecture = false /** * Run Proguard to shrink the Java bytecode in release builds. */ def enableProguardInReleaseBuilds = false /** * The preferred build flavor of JavaScriptCore. * * For example, to use the international variant, you can use: * `def jscFlavor = 'org.webkit:android-jsc-intl:+'` * * The international variant includes ICU i18n library and necessary data * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that * give correct results when using with locales other than en-US. Note that * this variant is about 6MiB larger per architecture than default. */ def jscFlavor = 'org.webkit:android-jsc:+' /** * Whether to enable the Hermes VM. * * This should be set on project.ext.react and mirrored here. If it is not set * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode * and the benefits of using Hermes will therefore be sharply reduced. */ def enableHermes = project.ext.react.get("enableHermes", false); android { compileSdkVersion rootProject.ext.compileSdkVersion compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } defaultConfig { applicationId "..." minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode ... versionName "..." missingDimensionStrategy 'react-native-camera', 'mlkit' multiDexEnabled true } dexOptions { javaMaxHeapSize "4g" } splits { abi { reset() enable enableSeparateBuildPerCPUArchitecture universalApk false // If true, also generate a universal APK include "armeabi-v7a", "x86", "arm64-v8a", "x86_64" } } signingConfigs { debug { storeFile file('...') storePassword '...' keyAlias '...' keyPassword '...' } release { if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) { storeFile file(MYAPP_RELEASE_STORE_FILE) storePassword MYAPP_RELEASE_STORE_PASSWORD keyAlias MYAPP_RELEASE_KEY_ALIAS keyPassword MYAPP_RELEASE_KEY_PASSWORD } } } buildTypes { debug { signingConfig signingConfigs.debug } releaseStaging { matchingFallbacks = ['release'] signingConfig signingConfigs.release } release { // Caution! In production, you need to generate your own keystore file. // see https://facebook.github.io/react-native/docs/signed-apk-android. // signingConfig signingConfigs.release minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" } } packagingOptions { pickFirst "lib/armeabi-v7a/libc++_shared.so" pickFirst "lib/arm64-v8a/libc++_shared.so" pickFirst "lib/x86/libc++_shared.so" pickFirst "lib/x86_64/libc++_shared.so" } // applicationVariants are e.g. debug, release applicationVariants.all { variant -> variant.outputs.each { output -> // For each separate APK per architecture, set a unique version code as described here: // https://developer.android.com/studio/build/configure-apk-splits.html def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4] def abi = output.getFilter(OutputFile.ABI) if (abi != null) { // null for the universal-debug, universal-release variants output.versionCodeOverride = versionCodes.get(abi) * 1048576 + defaultConfig.versionCode } } } } dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) //noinspection GradleDynamicVersion implementation "com.facebook.react:react-native:+" // From node_modules implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") { exclude group:'com.facebook.fbjni' } debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { exclude group:'com.facebook.flipper' } debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") { exclude group:'com.facebook.flipper' } // https://github.com/react-native-community/react-native-video#android-installation implementation "androidx.appcompat:appcompat:1.0.0" implementation 'com.android.support:multidex:1.0.3' if (enableHermes) { def hermesPath = "../../node_modules/hermes-engine/android/"; debugImplementation files(hermesPath + "hermes-debug.aar") releaseImplementation files(hermesPath + "hermes-release.aar") } else { implementation jscFlavor } } // Run this once to be able to run the application with BUCK // puts all compile dependencies into folder libs for BUCK to use task copyDownloadableDepsToLibs(type: Copy) { from configurations.compile into 'libs' } // Temporary fix for app bundle not starting with Hermes enabled // https://github.com/facebook/react-native/issues/26400#issuecomment-539395814 configurations.all { resolutionStrategy { force "com.facebook.soloader:soloader:0.8.0" } } apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) apply plugin: 'com.google.gms.google-services' ``` #### `android/settings.gradle`: ```groovy rootProject.name = '...' apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) include ':app', ':react-native-code-push' project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app') ``` #### `MainApplication.java`: ```java package com.test; import android.app.Application; import android.content.Context; import com.facebook.react.PackageList; import com.facebook.react.ReactApplication; import com.facebook.react.ReactInstanceManager; import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; import com.facebook.soloader.SoLoader; import java.lang.reflect.InvocationTargetException; import java.util.List; import com.microsoft.codepush.react.CodePush; public class MainApplication extends Application implements ReactApplication { 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 protected String getJSBundleFile() { return CodePush.getJSBundleFile(); } }; @Override public ReactNativeHost getReactNativeHost() { return mReactNativeHost; } @Override public void onCreate() { super.onCreate(); SoLoader.init(this, /* native exopackage */ false); initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); } /** * Loads Flipper in React Native templates. Call this in the onCreate method with something like * initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); * * @param context * @param reactInstanceManager */ private static void initializeFlipper( Context context, ReactInstanceManager reactInstanceManager) { 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.rndiffapp.ReactNativeFlipper"); aClass .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class) .invoke(null, context, reactInstanceManager); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } } ``` #### `AndroidManifest.xml`: ```xml ```


Environment

Click To Expand

**`react-native info` output:** ``` System: OS: Windows 10 CPU: (8) x64 Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz Memory: 4.44 GB / 15.93 GB Binaries: Node: 10.16.2 - C:\Program Files\nodejs\node.EXE Yarn: 1.19.1 - C:\Program Files (x86)\Yarn\bin\yarn.CMD npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD Watchman: Not Found SDKs: Android SDK: API Levels: 23, 25, 26, 27, 28, 29 Build Tools: 27.0.3, 28.0.2, 28.0.3, 29.0.2 System Images: android-27 | Google Play Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-Q | Google Play Intel x86 Atom Android NDK: Not Found IDEs: Android Studio: Version 3.3.0.0 AI-182.5107.16.33.5314842 Languages: Python: 2.7.15 - /c/Users/artur/.windows-build-tools/python27/python npmPackages: @react-native-community/cli: Not Found react: 16.11.0 => 16.11.0 react-native: 0.62.1 => 0.62.1 npmGlobalPackages: *react-native*: Not Found ``` - **Platform that you're experiencing the issue on**: - [ ] iOS - [ ] Android - [ ] **iOS** but have not tested behavior on Android - [x] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - `6.4.0` - **`Firebase` module(s) you're using that has the issue:** - `e.g. Instance ID` - **Are you using `TypeScript`?** - `N`


mikehardy commented 4 years ago

My recommendation is always: react-native-clean-project clean-project-auto

404-html commented 4 years ago

Thanks Mike. I tried following: npx react-native-clean-project with no luck. I'll try with clean-project-auto now.

mikehardy commented 4 years ago

The main thing is that it cleans DerivedData which is sometimes corrupt for me, and this shows up as debug vs release mode errors, so in CI I do this now, it's a little more specific so doesn't incur quite so much network transfer overhead rebuilding state, but I have 100% reliable release builds using it:

    "deep-clean": "./node_modules/.bin/react-native-clean-project --keep-node-modules --remove-iOS-build --keep-brew --keep-pods --remove-iOS-pods --remove-android-build && yarn clean",
    "clean": "\\rm -fr ./node_modules dist/* ios/build ios/Pods ios/KScoreApp.xcarchive android/build android/app/build public/js public/assets && yarn",
404-html commented 4 years ago

Thanks again Mike. Unfortunately I'm having the same problem after cleaning with different approaches. I've updated the description.

mikehardy commented 4 years ago

I wish I could help more but this still just seems like it's got be caching of some sort. package.json drives the versions, and compile processes render the versions into bundles and apps and the things run. Your package.json is saying 6.4.0 but what's trying to run is 6.3.4, ergo there must be a fail in the compilation somehow. Where? I took my best shot at the usual suspects but the area is still where I'd be looking

404-html commented 4 years ago

Okay, I'm pretty sure this was something on my side. Problem is gone after I set to@react-native-firebase packages version to 6.3.4. Thank you for your support @mikehardy 🍺

ezos86 commented 4 years ago

No solution for this?? I am seeing same thing, about to the point to restart the damn project. Ridiculous. I deleted everything 5+ times..

I end up getting it to work, by running the clean function from @mikehardy But one thing I would add is for it to automatically to reinstall pods. and also make sure you change your app name on it.

@404-html If you still need a solution try it. I deleted package-lock.json, deleted all node modules, double-checked my versions and then deleted all pods, and it didn't work, I needed to delete the archive and builds, cleaning the build in Xcode didn't work either. And make sure you delete the app on the simulator as well.

Updated command.

"clean": "\\rm -fr ./node_modules dist/* ios/build ios/Pods ios/{YOUR APP NAME}.xcarchive android/build android/app/build public/js public/assets && yarn && cd ios && pod install",
MRHuezo commented 4 years ago

Hello I am trying to implement react-native-firebase / messaging

I already installed This is my package dependencies "dependencies": { "@react-native-firebase/app": "^6.4.0", "@react-native-firebase/messaging": "^6.4.0", "react": "16.11.0", "react-native": "0.62.1" }

I have this code //1 const checkPermission = () => { messaging().hasPermission() .then(enabled => { if (enabled) { getToken(); } else { requestPermission(); } }) .catch(error => { console.log("error checking permisions " + error); }); };

//2 const requestPermission = () => { messaging().requestPermission() .then(() => { getToken(); }).catch(error => { console.log('permission rejected ' + error); }) };

//3 const getToken = () => { messaging().getToken() .then(token => { console.log("push token " + token) }).catch(error => { console.log("error getting push token " + error) }); };

I copy the gogle-service.json after to create a project on firebase console and add a application.

I got [messaging/unknown] AUTHENTICATION_FAILED

Thanks for your help

404-html commented 4 years ago

Reopening as people reporting that problem is still occurring.

AnasAlsaadi commented 4 years ago

any update? :)

mikehardy commented 4 years ago

There is no reproduction of this, no maintainer has seen it reproduced so I would not expect any response unless you can post a reproduction to github

Ehesp commented 4 years ago

Yep this is a local thing, nothing we can really do apart from suggest to wipe things. Remember there is more than just node_modules which are in play, native sides also have caches/lock files etc.

I've had success with https://www.npmjs.com/package/react-native-clean-project when things go wrong.

ezos86 commented 4 years ago

Yep this is a local thing, nothing we can really do apart from suggest to wipe things. Remember there is more than just node_modules which are in play, native sides also have caches/lock files etc.

I've had success with https://www.npmjs.com/package/react-native-clean-project when things go wrong.

It is a local thing and thanks for the recommended package. Maybe somewhere in docs it can be added as an (If condition) when people are updating. 👍

dnero commented 4 years ago

I had this same error pop up today as I was trying to add @react-native-firebase/storage, but after a second glance, the error is complaining about @react-native-firebase/app being of a different version.

Personally, I always lock my (package.json) versions and do manual updates. When I originally started, my @react-native-firebase/app version was v6.3.4. I later added @react-native-firebase/storage and by then the version was v6.4.0 for @react-native-firebase/storage.

The problem here is that @react-native-firebase/app is the core and its version seemingly must be >= any other @react-native-firebase packages. Simply updating @react-native-firebase/app to v6.4.0 did the trick.