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

Remote config/ failure fetch operation cannot be completed successfully. #4031

Closed aayushsin closed 4 years ago

aayushsin commented 4 years ago

Issue

I have configured the latest "@react-native-firebase/remote-config" and it somehow fails to fetch a single remote config in my firebase. As fetchAndActivate API is not working, I am using the workaround as mentioned in https://github.com/invertase/react-native-firebase/issues/2767.

export const getRemoteConfig = async () => {
    let configProps = {};
  let configData;
  remoteConfig().setConfigSettings({
    minimumFetchIntervalMillis: 0,
  });
  await remoteConfig().setDefaults({
    recipe_feature: false,
  });
  try {
    await remoteConfig().fetch();
    const activated = await remoteConfig().activate();
    if (!activated) console.log('Remote Config not activated');
    const parameters = remoteConfig().getAll();
    console.log(parameters);

    Object.keys(parameters).forEach((entry) => {
      configData = remoteConfig().getValue(entry);
      configProps[entry] = configData._value == 'true' ? true : false;
    });
  } catch {
    console.log('No internet');
    configProps['recipe_feature'] = false;
  }
  const response = { data: configProps };
  return response;
};

When the internet connectivity is turned off, this function returns an error: [remoteConfig/failure] fetch() operation cannot be completed successfully.

However, it is still unable to activate the remote config. But the fetch is successfull. As a workaround, I had to create a redux store to store the flags.

Why do I need to call feature._value to get the value? The feature.value returns undefined.

Project Files

Javascript

Click To Expand

#### `package.json`: ```json "dependencies": { "@eva-design/eva": "^2.0.0", "@eva-design/material": "^2.0.0", "@react-native-community/async-storage": "^1.11.0", "@react-native-community/google-signin": "^4.0.3", "@react-native-community/masked-view": "^0.1.10", "@react-native-firebase/analytics": "^7.1.4", "@react-native-firebase/app": "^8.2.0", "@react-native-firebase/auth": "^8.0.5", "@react-native-firebase/crashlytics": "^8.1.2", "@react-native-firebase/database": "^7.2.2", "@react-native-firebase/dynamic-links": "^7.1.4", "@react-native-firebase/firestore": "^7.1.7", "@react-native-firebase/iid": "^7.1.4", "@react-native-firebase/in-app-messaging": "^7.1.4", "@react-native-firebase/messaging": "^7.1.5", "@react-native-firebase/perf": "^7.1.4", "@react-native-firebase/remote-config": "^8.0.0", "@react-native-firebase/storage": "^7.1.4", "@react-navigation/bottom-tabs": "^5.7.2", "@react-navigation/core": "^5.12.1", "@react-navigation/drawer": "^5.8.6", "@react-navigation/material-top-tabs": "^5.2.14", "@react-navigation/native": "^5.7.1", "@react-navigation/stack": "^5.7.1", "@types/react-native-snap-carousel": "^3.8.1", "@ui-kitten/components": "^5.0.0", "@ui-kitten/date-fns": "^5.0.0", "@ui-kitten/eva-icons": "^5.0.0", "@ui-kitten/moment": "^5.0.0", "axios": "^0.19.2", "date-fns": "^2.15.0", "expo": "^37.0.12", "expo-asset": "^8.1.7", "expo-constants": "^9.1.1", "expo-font": "^8.2.1", "expo-web-browser": "^8.3.1", "i18next": "^19.6.2", "ingredients-parser": "^1.4.0", "moment": "^2.27.0", "react": "^16.13.1", "react-dom": "^16.13.1", "react-i18next": "^11.7.0", "react-native": "^0.62.2", "react-native-appearance": "^0.3.4", "react-native-camera": "^3.32.0", "react-native-device-info": "^5.6.2", "react-native-floating-action": "^1.20.0", "react-native-gesture-handler": "^1.6.1", "react-native-image-slider-box": "^1.0.12", "react-native-keyboard-aware-scroll-view": "^0.9.1", "react-native-modal-selector": "^2.0.1", "react-native-permissions": "^2.1.5", "react-native-qrcode-scanner": "^1.3.2", "react-native-reanimated": "^1.9.0", "react-native-safari-view": "^2.1.0", "react-native-safe-area-context": "^3.0.2", "react-native-screens": "^2.9.0", "react-native-simple-toast": "^1.1.2", "react-native-snap-carousel": "^3.9.1", "react-native-svg": "9.13", "react-native-swipe-list-view": "^3.1.1", "react-native-tab-view": "^2.15.0", "react-native-web": "^0.11.7", "react-redux": "^7.2.0", "redux": "^4.0.5", "redux-logger": "^3.0.6", "redux-persist": "^6.0.0", "redux-thunk": "^2.3.0", "remote-redux-devtools": "^0.5.16" }, "devDependencies": { "@babel/core": "^7.10.5", "@babel/runtime": "^7.10.5", "@expo/webpack-config": "^0.12.20", "@types/lodash": "^4.14.157", "@types/react": "^16.9.43", "@types/react-native": "^0.62.13", "babel-plugin-module-resolver": "^4.0.0", "babel-preset-expo": "^8.2.3", "body-parser": "^1.19.0", "conventional-changelog-cli": "^2.0.21", "expo-cli": "^3.22.3", "express": "^4.17.1", "husky": "^4.2.5", "jetifier": "^1.6.6", "lodash": "^4.17.19", "prettier": "^2.0.5", "rimraf": "^3.0.2", "tslint": "^6.0.0", "tslint-config-prettier": "^1.18.0", "typescript": "^3.9.7" } ``` #### `firebase.json` for react-native-firebase v6: ```json # N/A ```

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? - [x] I am using the NPM package `jetifier` for react-native compatibility? #### `android/build.gradle`: ```groovy buildscript { ext { buildToolsVersion = "28.0.3" minSdkVersion = 21 compileSdkVersion = 28 targetSdkVersion = 28 googlePlayServicesVersion = "+" // default: "+" firebaseVersion = "17.3.4" // default: "+" } repositories { google() jcenter() mavenCentral() maven { url 'https://maven.fabric.io/public' } } dependencies { classpath("com.android.tools.build:gradle:3.4.2") classpath("com.google.gms:google-services:4.3.3") classpath 'io.fabric.tools:gradle:1.28.1' } } allprojects { repositories { mavenLocal() google() maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url("$rootDir/../node_modules/react-native/android") } maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url("$rootDir/../node_modules/react-native-camera/android") } maven { // Android JSC is installed from npm url("$rootDir/../node_modules/jsc-android/dist") } jcenter() maven { url 'https://jitpack.io' } } } ``` #### `android/app/build.gradle`: ```groovy apply plugin: "com.android.application" apply plugin: 'io.fabric' apply plugin: "com.google.gms.google-services" 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" def enableSeparateBuildPerCPUArchitecture = false def enableProguardInReleaseBuilds = false def jscFlavor = 'org.webkit:android-jsc:+' 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 "app.alpha" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 6 versionName "0.0.2" missingDimensionStrategy 'react-native-camera', 'general' 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('debug.keystore') storePassword 'android' keyAlias 'androiddebugkey' keyPassword 'android' } release { if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) { storeFile file(MYAPP_UPLOAD_STORE_FILE) storePassword MYAPP_UPLOAD_STORE_PASSWORD keyAlias MYAPP_UPLOAD_KEY_ALIAS keyPassword MYAPP_UPLOAD_KEY_PASSWORD } } } buildTypes { debug { signingConfig signingConfigs.debug } release { signingConfig signingConfigs.release minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" } } 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"]) implementation "com.facebook.react:react-native:+" // From node_modules implementation 'androidx.appcompat:appcompat:1.1.0-rc01' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02' if (enableHermes) { def hermesPath = "../../node_modules/hermes-engine/android/"; debugImplementation files(hermesPath + "hermes-debug.aar") releaseImplementation files(hermesPath + "hermes-release.aar") } else { implementation jscFlavor } } 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 rootProject.name = 'Alpha' include ':react-native-permissions' project(':react-native-permissions').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-permissions/android') include ':react-native-camera' project(':react-native-camera').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-camera/android') apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) include ':app' ``` #### `MainApplication.java`: ```java // N/A ``` #### `AndroidManifest.xml`: ```xml ```


Environment

Click To Expand

**`react-native info` output:** ``` System: OS: Windows 10 10.0.19041 CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz Memory: 1.20 GB / 7.89 GB Binaries: Node: 13.9.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.0 - ~\AppData\Roaming\npm\yarn.CMD npm: 6.13.7 - C:\Program Files\nodejs\npm.CMD Watchman: Not Found SDKs: Android SDK: API Levels: 23, 26, 27, 28, 29 Build Tools: 28.0.3, 29.0.2 System Images: android-26 | Google APIs Intel x86 Atom_64, android-27 | Google APIs Intel x86 Atom, android-28 | Intel x86 Atom, android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom_64, android-28 | Google Play Intel x86 Atom, android-29 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom_64 Android NDK: Not Found IDEs: Android Studio: Not Found Languages: Java: 12.0.1 Python: 3.7.1 npmPackages: @react-native-community/cli: Not Found react: ^16.13.1 => 16.13.1 react-native: ^0.62.2 => 0.62.2 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:** - `"@react-native-firebase/remote-config": "^8.0.0",` - **`Firebase` module(s) you're using that has the issue:** - `remote-config` - **Are you using `TypeScript`?** - `Y` & `3.9.7`


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.

Findiglay commented 4 years ago

Experiencing same issue:

NativeFirebaseError: [remoteConfig/failure] fetch() operation cannot be completed successfully.
mikehardy commented 4 years ago

@Findiglay there has been a breaking change release on remote config since this was logged. Please upgrade to current stable versions, open a new issue if the (newly / more correctly documented) APIs do not perform as expected vs their documentation

CHANDRAMOHANnegi commented 3 years ago

NativeFirebaseError: [remoteConfig/failure] fetch() operation cannot be completed successfully. at FirebaseConfigModule.fetch (index.js:180) at fetchData (index.js:188) at App.componentDidMount$ (App.js:71) at tryCatch (runtime.js:63) at Generator.invoke [as _invoke] (runtime.js:293) at Generator.next (runtime.js:118) at tryCatch (runtime.js:63) at invoke (runtime.js:154) at runtime.js:189

This issue on emulator , Working fine on device.
mikehardy commented 3 years ago

With apologies @CHANDRAMOHANnegi that's not useful without knowing why it failed. Device logs (e.g., adb logcat unfiltered) will help explain it I think, plus you are posting on an issue closed in 2020, there will be no further traffic here, sorry.

If you can post a https://stackoverflow.com/help/minimal-reproducible-example on a new issue we may investigate?

gigeos commented 2 years ago

Hie @mikehardy I can repoduce the issue too.

Issue

When I turn off the connection to test my app offline behavior, I experience the same issue when launching app: NativeFirebaseError: [remoteConfig/failure] fetch() operation cannot be completed successfully.

Version "@react-native-firebase/app": "12.9.1", "@react-native-firebase/crashlytics": "12.9.1", "@react-native-firebase/remote-config": "^13.0.1", "react-native": "0.65.1",

My code

const CONFIGS: RemoteConfig = {
  minimumVersion: '{"production": "1.0.0", "staging": "1.0.0"}',
  canLoginWithFacebook: '{"production": true, "staging": true}',
};

const readingAllConfigs = () => {
   const allConfigs = remoteConfig().getAll();
    return Object.entries(allConfigs).reduce((acc, current) => {
      const [key, entry] = current;
      acc[key] = {
        source: entry.getSource(),
        value: convertEntryToValue(key as RemoteConfigKeys, entry),
      };
      return acc;
  }, {} as Configs);
}

export const initFeatureFlags = async () => {
  try {
    await remoteConfig().fetch(300);
    await remoteConfig().setDefaults(CONFIGS);
    await remoteConfig().fetchAndActivate();
    const allConfigs = readingAllConfig();
    return allConfigs;
  } catch (error) {
    // the error which is catched
    console.error('error);
  }
};
mikehardy commented 2 years ago

Oh no! Do not do this mix-and-match thing:

"@react-native-firebase/app": "12.9.1",
"@react-native-firebase/crashlytics": "12.9.1",
"@react-native-firebase/remote-config": "^13.0.1",

https://invertase.io/blog/react-native-firebase-versioning

I think we need a new issue open on this if you can still reproduce with current versions - a single App.js that can drop in to a clean container like https://github.com/mikehardy/rnfbdemo/blob/master/make-demo.sh would be appreciated

gigeos commented 2 years ago

Yes indeed while posting my answer I saw that the versions were not aligned (and a message in Metro warn about that). So I put everything in 13.0.1 and it works fine πŸ™ˆ Sorry for the inconvenience Mike!

approached commented 2 years ago

Same problem... just check your internet connection on mobile emulator

amitpdev commented 8 months ago

Insure the API key you are using has the proper credentials! Find the api_key under google-services.json on your project. then find that key in google cloud console, Insure it has "Firebase Remote Config API" checked. too bad this step is not mentioned anywhere on Firebase documentation for RC.

juanbalofredo commented 1 month ago

I just had this problem, which turned out to be because I had a google-services.json from one Firebase project. I deleted that Firebase project, switched to another one, added the new google-services.json, but it kept taking the ID from the previous Firebase project. I debugged it by looking at the log of remoteConfig(), and fixed my problem with a new build.

Juan2662 commented 1 month ago

In my case I had to do this

In your google cloud project select your project and find your Android Key (created by Firebase) image If you have set up restrictions for your app as "Android apps", make sure you have added the Package name and fingerprint values ​​for your app You can get the fingerprint value running "./gradlew signingReport" from "rootProject/android" Screenshot 2024-07-31 at 15 41 57

This work's for me on android emulator