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

🔥[🐛] Error: FirebaseApp with name {project_number} doesn't exist. Avilable app names: [DEFAULT] #6710

Closed Ellathet closed 1 year ago

Ellathet commented 1 year ago

Issue

When I build a release apk, and open it for second time, it return to me this error. This happened after I changed the version to latest, that error happen's only in build release, debug version is running normaly.

Project Files

Javascript

Click To Expand

#### `package.json`: ```json "dependencies": { "@react-native-community/async-storage": "^1.11.0", "@react-native-community/masked-view": "^0.1.10", "@react-native-community/netinfo": "^5.9.2", "@react-native-community/picker": "^1.6.6", "@react-native-community/progress-bar-android": "^1.0.3", "@react-native-firebase/app": "^16.4.3", "@react-native-firebase/crashlytics": "^16.4.3", "@react-native-firebase/messaging": "^16.4.3", "@react-navigation/bottom-tabs": "^5.2.1", "@react-navigation/native": "^5.1.3", "@react-navigation/stack": "^5.2.8", "@valdio/react-native-scrollable-tabview": "^0.8.12", "axios": "^0.19.2", "caniuse-lite": "^1.0.30001365", "fbjs": "^3.0.4", "i": "^0.3.6", "jail-monkey": "^2.6.0", "lottie-ios": "3.1.8", "lottie-react-native": "4.0.2", "md5": "^2.2.1", "moment": "^2.24.0", "moment-timezone": "^0.5.28", "native-base": "^2.13.12", "npm": "^6.14.2", "react": "16.11.0", "react-feather": "^2.0.3", "react-native": "0.62.2", "react-native-animatable": "^1.3.3", "react-native-autolink": "^3.0.0", "react-native-blob-util": "^0.14.0", "react-native-camera": "^3.35.0", "react-native-charts-wrapper": "^0.5.7", "react-native-code-push": "^7.0.5", "react-native-collapsible": "^1.5.3", "react-native-config": "^1.4.6", "react-native-create-thumbnail": "^1.2.2", "react-native-device-info": "^5.6.5", "react-native-easy-grid": "^0.2.2", "react-native-exit-app": "^1.1.0", "react-native-fast-image": "^8.3.4", "react-native-fix-image": "^2.0.1", "react-native-fs": "^2.16.6", "react-native-gesture-handler": "^1.7.0", "react-native-html-to-pdf": "^0.11.0", "react-native-i18n": "^2.0.15", "react-native-image-picker": "^4.8.4", "react-native-keep-awake": "^4.0.0", "react-native-keyboard-aware-scroll-view": "^0.9.2", "react-native-localize": "^1.3.4", "react-native-masked-text": "^1.13.0", "react-native-modal": "^11.5.6", "react-native-orientation-locker": "^1.5.0", "react-native-pager-view": "5.4.6", "react-native-parsed-text": "0.0.21", "react-native-pdf": "^6.4.0", "react-native-pdf-lib": "1.0.0", "react-native-permissions": "^2.1.5", "react-native-picker-select": "^8.0.0", "react-native-progress-circle": "^2.1.0", "react-native-push-notification-popup": "^1.4.0", "react-native-reanimated": "^1.13.0", "react-native-render-html": "^6.3.4", "react-native-safe-area-context": "^3.1.4", "react-native-safe-area-view": "^1.1.1", "react-native-screens": "^2.10.1", "react-native-simple-radio-button": "^2.7.4", "react-native-snap-carousel": "^3.9.1", "react-native-svg": "^12.0.3", "react-native-swift": "^1.2.3", "react-native-tab-view": "^2.15.1", "react-native-text-ticker": "^1.10.0", "react-native-track-player": "none", "react-native-vector-icons": "^7.0.0", "react-native-video": "^5.2.0", "react-native-webview": "none", "react-navigation-redux-helpers": "^4.0.1", "react-redux": "^7.2.0", "redux": "^4.0.5", "redux-thunk": "^2.3.0", "seamless-immutable": "^7.1.4", "styled-components": "^5.0.1" }, "devDependencies": { "@babel/core": "^7.8.7", "@babel/runtime": "^7.8.7", "@react-native-community/eslint-config": "^0.0.7", "babel-jest": "^25.1.0", "cors": "^2.8.5", "eslint": "^6.8.0", "eslint-config-airbnb": "^18.1.0", "eslint-plugin-babel": "^5.3.0", "eslint-plugin-import": "^2.20.1", "eslint-plugin-jest": "^23.8.2", "eslint-plugin-jsx-a11y": "^6.2.3", "eslint-plugin-react-hooks": "^2.5.0", "jest": "^25.1.0", "metro-react-native-babel-preset": "^0.58.0", "patch-package": "^6.5.0", "postinstall-postinstall": "^2.1.0", "react-native-dotenv": "^3.3.0", "react-native-svg-transformer": "^0.14.3", "react-test-renderer": "16.9.0" } ```


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 // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { buildToolsVersion = "29.0.3" compileSdkVersion = 31 targetSdkVersion = 31 minSdkVersion = 21 supportLibVersion = "29.0.2" reactNativeVersion = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim()) } repositories { google() jcenter() maven { url 'https://maven.fabric.io/public' } } dependencies { classpath 'com.android.tools.build:gradle:4.0.1' classpath 'com.google.gms:google-services:4.3.14' classpath 'io.fabric.tools:gradle:1.28.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { configurations.all { resolutionStrategy { force "com.facebook.react:react-native:" + reactNativeVersion } } repositories { google() 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://jitpack.io' } } } ``` #### `android/app/build.gradle`: ```groovy apply plugin: "com.android.application" apply plugin: 'com.google.gms.google-services' apply plugin: 'io.fabric' apply from: "../../node_modules/react-native-vector-icons/fonts.gradle" apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle" import com.android.build.OutputFile project.ext.react = [ entryFile : "index.js", enableHermes: false, // clean and rebuild if changing ] apply from: "../../node_modules/react-native/react.gradle" apply from: "../../node_modules/react-native-code-push/android/codepush.gradle" def enableSeparateBuildPerCPUArchitecture = false def enableProguardInReleaseBuilds = false def jscFlavor = 'org.webkit:android-jsc:+' def enableHermes = project.ext.react.get("enableHermes", false); crashlytics { enableNdk true } android { dexOptions { jumboMode = true } compileSdkVersion rootProject.ext.compileSdkVersion compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } defaultConfig { missingDimensionStrategy 'react-native-camera', 'general' minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 45 versionName "1.1.2" multiDexEnabled true } 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('keys/debug.keystore') storePassword 'android' keyAlias 'androiddebugkey' keyPassword 'android' } } buildTypes { debug { signingConfig signingConfigs.debug } release { // Caution! In production, you need to generate your own keystore file. // see https://facebook.github.io/react-native/docs/signed-apk-android. minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" } } flavorDimensions "default" productFlavors { produtodev { applicationId "my.app.id dimension "default" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion } } sourceSets { main { res.srcDirs += ['src/main/res'] } } // 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 } } } packagingOptions { pickFirst '**/armeabi-v7a/libc++_shared.so' pickFirst '**/x86/libc++_shared.so' pickFirst '**/arm64-v8a/libc++_shared.so' pickFirst '**/x86_64/libc++_shared.so' pickFirst '**/x86/libjsc.so' pickFirst '**/armeabi-v7a/libjsc.so' } } dependencies { implementation project(':react-native-device-info'); implementation fileTree(dir: "libs", include: ["*.jar"]); implementation "com.facebook.react:react-native:+"; implementation project(':react-native-config'); implementation project(':react-native-i18n'); implementation project(':react-native-exit-app'); implementation project(':react-native-video'); implementation project(':react-native-pdf-lib'); implementation "androidx.appcompat:appcompat:1.0.0"; 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' } apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) ``` #### `android/settings.gradle`: ```groovy include ':react-native-track-player' project(':react-native-track-player').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-track-player/android') include ':react-native-config' project(':react-native-config').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-config/android') include ':react-native-pdf-lib' project(':react-native-pdf-lib').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-pdf-lib/android') include ':react-native-exit-app' project(':react-native-exit-app').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-exit-app/android') include ':react-native-track-player' project(':react-native-track-player').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-track-player/android') include ':@react-native-community_picker' project(':@react-native-community_picker').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/picker/android') include ':react-native-device-info' project(':react-native-device-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-device-info/android') apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) include ':app', ':react-native-i18n' project(':react-native-i18n').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-i18n/android') include ':react-native-exit-app', ':app' project(':react-native-exit-app').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-exit-app/android') include ':react-native-video' project(':react-native-video').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-video/android-exoplayer') include ':app', ':react-native-code-push' project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app') include ':app' ``` #### `MainApplication.java`: ```java import android.app.Application; import android.content.Context; import com.facebook.react.PackageList; import com.facebook.react.ReactApplication; import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; import com.facebook.soloader.SoLoader; import java.lang.reflect.InvocationTargetException; import org.wonday.orientation.OrientationPackage; import java.util.List; import com.github.wumke.RNExitApp.RNExitAppPackage; import com.brentvatne.react.ReactVideoPackage; import com.microsoft.codepush.react.CodePush; public class MainApplication extends Application implements ReactApplication { private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { @Override protected String getJSBundleFile() { return CodePush.getJSBundleFile(); } @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(); packages.add( new ReactVideoPackage()); return packages; } @Override protected String getJSMainModuleName() { return "index"; } }; @Override public ReactNativeHost getReactNativeHost() { return mReactNativeHost; } @Override public void onCreate() { super.onCreate(); SoLoader.init(this, /* native exopackage */ false); //initializeFlipper(this); // Remove this line if you don't want Flipper enabled } /** * 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(); } } } } ``` #### `AndroidManifest.xml`: ```xml ```

I use the a lot of flavors

Environment

**`react-native info` output:** ``` Android Studio: AI-212.5712.43.2112.8609683 Visual Studio: Not Found Languages: Java: 11.0.17 - /c/Program Files/Eclipse Adoptium/jdk-11.0.17.8-hotspot/bin/javac Python: 3.10.5 - /c/Users/socia/AppData/Local/Programs/Python/Python310/python npmPackages: @react-native-community/cli: Not Found react: 16.11.0 => 16.11.0 react-native: 0.62.2 => 0.62.2 react-native-windows: Not Found npmGlobalPackages: *react-native*: Not Found ``` - **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-firebase` version you're using that has this issue:** - `v16.4.3` - **`Firebase` module(s) you're using that has the issue:** - `@react-native-firebase/app` - `@react-native-firebase/crashlytics` - `@react-native-firebase/messaging` - No typescript

mikehardy commented 1 year ago

Sorry, not enough information to go on, not even a complete stack trace, much less sample code https://stackoverflow.com/help/how-to-ask https://stackoverflow.com/help/minimal-reproducible-example

My only guess is that the last time I've seen strange issues like this where there were differences in debug and release on android,

    "react-native-code-push": "^7.0.5",

it was from code push dropping a bundle in to the app that was unexpected.

Perhaps that's it

Ellathet commented 1 year ago

Right, I don't have a code, simply my app closes when I start for the second time. The only thing I changed was the react-native-fireabse version. And informations in gradlew, and dependencies.

I really had problems with code-push, but I uploaded the version of google-services:4.3.14, in my android build.gradlew:

classpath 'com.google.gms:google-services:4.3.14'

Are there any indications for the google services version?

The app doesn't crash in debug, only in release, so I don't have a code. The code itself works in debug.

mikehardy commented 1 year ago

revert your change to firebase versions, try again I really don't have anything concrete to offer you, as you have not offered me anything concrete to use to help you https://stackoverflow.com/help/how-to-ask

But as a general troubleshooting measure, if you make a change and it breaks, reverse the change, see if it still breaks. If it still breaks, you have some other problem, not the change you thought cause it... etc

mikehardy commented 1 year ago

Without more concrete information I won't be able to comment further, apologies.

Ellathet commented 1 year ago

Oh sorry.

I'll try to put some more code here, to try to help you... which is difficult, because it works in debug...

But all I found of this same error was solutions like:

I don't uderstand this answer

This question solution, don't running, because I use the flavors options spoken in this issues.

This is similar, but in flutter.

The problem is that I don't have practical examples either, just my app closing and showing an error like this: Screenshot_2022-11-17-17-48-31-518_com miui bugreport

Ellathet commented 1 year ago

Using these same library versions, which I use in my gradlew and react-native-firebase. You wouldn't be able to reproduce?

Because the use of firebase in the application is nothing more than the example that is in the documentation... ;-;

I'm trying to do the rollback you mentioned, thanks

mikehardy commented 1 year ago

This works, it tests release mode as well: https://github.com/mikehardy/rnfbdemo/blob/main/make-demo.sh

Ellathet commented 1 year ago

I did the downgrade to: 14.12.0, it's work.

But when I did the downgrade to 9.0.0, 8.0.3..., not works. Go figure >,<

Thanks for helping...

mikehardy commented 1 year ago

That's unexpected, the use frameworks change is major but other than that there is nothing that should affect app registration https://github.com/invertase/react-native-firebase/blob/main/CHANGELOG.md#1500-2022-06-20

Maybe make sure you have up to date firebase plist and JSON files downloaded, and that the app bundles really are not coming in with mismatch from code push (maybe temporarily disable it even)

thilook commented 1 year ago

Hello @mikehardy I work with @Ellathet on this same project. We were able to narrow down a little bit the issue. The issue at first it's only being noticed on release versions (apk, aab) and only happens when the app is brought from the background state. When we disable code-push the issue seems to stop happening what lead us to believe that the codePush.sync() function is messing something with the bundle. When downgrading firebase to 14.2.2 we receive an issue simillar to the one described here. We still investigating to see if everything is working correctly without code-push but if you have any suggestions of how we could add back code-push as well. Thank you very much for the help so far.

mikehardy commented 1 year ago

5719 is a native-code / javascript-code API mismatch error, which is another indicator of an "unexpected bundle", and could be caused by code push.

I suggest that you make sure code-push does not download/use bundles that are built with incompatible versions of the native code. When react-native-firebase issues semantic-version major version changes, that implies that APIs have changed and things are no longer compatible across the native / javascript boundary.

mihir0x69 commented 1 year ago

Seeing the exact same issue 😞 I can also confirm that it happens after we apply codepush updates. Can someone please elaborate how firebase and codepush are tangled?

mikehardy commented 1 year ago

I'm afraid that elaboration will have to be done by someone using codepush and react-native-firebase, which is the commenters here including yourself. As I understand it there are many using codepush successfully, so it is not just codepush + react-native-firebase, it is something project-specific in the way you are using react-native-firebase inside the bundle that is causing the issue. I can't guess what that will be, but it clearly has something to do with Firebase "app" initialization / configuration

If there were more information it might be possible to help.

https://stackoverflow.com/help/how-to-ask https://stackoverflow.com/help/minimal-reproducible-example