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.72k stars 2.22k forks source link

[🐛] Firebase remote config fetch failing on subsequent attempts #7555

Closed trickeyd closed 9 months ago

trickeyd commented 10 months ago

Issue

Describe your issue here

Thanks for the work you do - I have hit a bit of a snag though 😄

After updating @react-native-firebase libraries to version 18.5.0, fetching Remote Config values works initially, but fails on subsequent attempts. The issue seems to be related to caching, and calling remoteConfig().reset() before each fetch resolves the problem. This is not ideal though, and was not needed before the update.

The update was forced when I updated out react native appodeal, which in turn forced many updates including firebase, due to the large number of native SDKs involved, so there. could be some interference from them. I'll include the main ones below:

Another thing that happened at exactly the same time, and may have had an effect was the source for boost becoming redundant. I have added patches to react-native-reanimated, expo-modules-core and react-native itself to download boost from a different source. This is probably nothing to do with it, but I cant rule it out as everything happened simultaneously. This issue is outlined here: https://github.com/software-mansion/react-native-reanimated/issues/5542

When it fails, there is no error to catch in the JS, and this is the logcat:

2024-01-09 11:51:42.051 8526-8763/com.goss.prerelease D/RNFBCrashlyticsInit: isCrashlyticsCollectionEnabled via RNFBMeta: true
2024-01-09 11:51:42.052 8526-8763/com.goss.prerelease D/RNFBCrashlyticsInit: isCrashlyticsCollectionEnabled after checking crashlytics_debug_enabled: false
2024-01-09 11:51:42.055 8526-8763/com.goss.prerelease D/RNFBCrashlyticsInit: isCrashlyticsCollectionEnabled final value: false
2024-01-09 11:51:42.055 8526-8763/com.goss.prerelease I/Crashlytics: crashlytics collection is not enabled, not crashing.
2024-01-09 11:51:42.098 8526-8728/com.goss.prerelease D/IBG-Core: inserting network log
2024-01-09 11:51:42.102 8526-8794/com.goss.prerelease D/IBG-APM: adding network log: APMNetworkLog{startTime=1704801102044000, url='http://localhost:8081/symbolicate', method='POST', requestHeaders='{"content-type":"text\/plain;charset=UTF-8"}', responseHeaders='{"cache-control":" no-store, no-cache, must-revalidate, proxy-revalidate","connection":" keep-alive","date":" Tue, 09 Jan 2024 21:55:32 GMT","expires":" 0","keep-alive":" timeout=30","pragma":" no-cache","surrogate-control":" no-store","transfer-encoding":" chunked","x-content-type-options":" nosniff"}', requestContentType='text/plain', responseContentType='', errorMessage='null', totalDuration=43, responseCode=200, requestBodySize=4033, responseBodySize=4725, requestBody='{"stack":[{"methodName":"addLog","file":"http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.goss.prerelease&modulesOnly=false&runModule=true","lineNumber":20855,"column":38},{"methodName":"registerWarning","file":"http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.goss.prerelease&modulesOnly=false&runModule=true","lineNumber":20603,"column":29},{"methodName":"anonymous","file":"http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.goss.prerelease&modulesOnly=false&runModule=true","lineNumber":20532,"column":33},{"methodName":"overrideMethod","file":"http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.goss.prerelease&modulesOnly=false&runModule=true","lineNumber":32742,"column":38},{"methodName":"anonymous","file":"http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.goss.prerelease&modulesOnly=false&runModule=true","lineNumber":135643,"column":14},{"methodName":"logError","file":"http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.goss.prerelease&modulesOnly=false&runModule=true","lineNumber":159304,"column":18},{"methodName":"?anon_0_","file":"http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.goss.prerelease&modulesOnly=false&runModule=true","lineNumber":167615,"column":82},{"methodName":"asyncGeneratorStep","file":"http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.goss.prerelease&modulesOnly=false&runModule=true","lineNumber":1192,"column":25},{"methodName":"_next","file":"http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.goss.prerelease&modulesOnly=false&runModule=true","lineNumber":1211,"column":28},{"methodName":"tryCallOne","file":"/root/react-native/ReactAndroid/hermes-engine/.cxx/Release/3f4v354d/arm64-v8a/lib/InternalBytecode/InternalBytecode.js","lineNumber":53,"column":15},{"methodName":"anonymous","file":"/root/react-native/ReactAndroid/hermes-engine/.cxx/Release/3f4v354d/arm64-v8a/lib/InternalBytecode/InternalBytecode.js","lineNumber":139,"column":26},{"methodName":"anonymous","file":"http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.goss.prerelease&modulesOnly=false&runModule=true","lineNumber":26778,"column":25},{"methodName":"_callTimer","file":"http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.goss.prerelease&modulesOnly=false&runModule=true","lineNumber":26697,"column":16},{"methodName":"_callReactNativeMicrotasksPass","file":"http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.goss.prerelease&modulesOnly=false&runModule=true","lineNumber":26727,"column":16},{"methodName":"callReactNativeMicrotasks","file":"http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.goss.prerelease&modulesOnly=false&runModule=true","lineNumber":26890,"column":43},{"methodName":"__callReactNativeMicrotasks","file":"http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.goss.prerelease&modulesOnly=false&runModule=true","lineNumber":5099,"column":45},{"methodName":"anonymous","file":"http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.goss.prerelease&m
2024-01-09 11:51:42.102 8526-8794/com.goss.prerelease D/IBG-APM: 
2024-01-09 11:51:42.110 8526-8840/com.goss.prerelease D/IBG-APM: Network request added to network table: http://localhost:8081/symbolicate
2024-01-09 11:51:42.118 8526-8840/com.goss.prerelease D/IBG-APM: inserted network log, returning: 48
2024-01-09 11:51:42.349 8526-8670/com.goss.prerelease D/EGL_emulation: app_time_stats: avg=5.08ms min=2.57ms max=17.30ms count=59

package.json:

{
  "dependencies": {
    "react-native-appodeal": "3.2.1",
    "react-native-appsflyer": "6.12.2",
    "react-native-fbsdk-next": "12.1.2",
    "@react-native-firebase/analytics": "18.5.0",
    "@react-native-firebase/app": "18.5.0",
    "@react-native-firebase/auth": "18.5.0",
    "@react-native-firebase/crashlytics": "18.5.0",
    "@react-native-firebase/messaging": "18.5.0",
    "@react-native-firebase/remote-config": "18.5.0"
    // Add other dependencies if relevant
  }
}

Javascript

         // broken
          await remoteConfig().fetch()
          const configsWereRetrieved = await remoteConfig().activate()
          console.log(configsWereRetrieved) // true first time, but the false even after app hard close
       // fixed(ish)
       await remoteConfig().reset()
       await remoteConfig().fetch()
       const configsWereRetrieved = await remoteConfig().activate()
       console.log(configsWereRetrieved) // works, but defeats point in cache

I have also tried most combinations of these initialisation functions, such as the ones outlined here: https://github.com/invertase/react-native-firebase/issues/2767

package.json:

  "dependencies": {
    "@formatjs/intl-datetimeformat": "4.1.5",
    "@formatjs/intl-locale": "2.4.40",
    "@fortawesome/fontawesome-pro": "6.4.2",
    "@fortawesome/fontawesome-svg-core": "6.4.2",
    "@fortawesome/free-brands-svg-icons": "6.4.2",
    "@fortawesome/pro-light-svg-icons": "6.4.2",
    "@fortawesome/pro-regular-svg-icons": "6.4.2",
    "@fortawesome/pro-solid-svg-icons": "6.4.2",
    "@fortawesome/react-fontawesome": "0.2.0",
    "@fortawesome/react-native-fontawesome": "0.3.0",
    "@gorhom/bottom-sheet": "^4.5.0",
    "@idiosync/fswitch": "1.0.24",
    "@idiosync/horizontal-flatlist": "1.0.18",
    "@idiosync/react-native-modal": "1.2.14",
    "@idiosync/telescope": "2.1.14",
    "@invertase/react-native-apple-authentication": "1.1.1",
    "@jridgewell/trace-mapping": "0.3.13",
    "@react-native-async-storage/async-storage": "1.17.10",
    "@react-native-community/art": "1.2.0",
    "@react-native-community/blur": "4.3.0",
    "@react-native-community/cli-platform-android": "10.1.0",
    "@react-native-community/datetimepicker": "4.0.1",
    "@react-native-community/netinfo": "9.0.0",
    "@react-native-community/push-notification-ios": "1.10.1",
    "@react-native-community/slider": "2.0.8",
    "@react-native-firebase/analytics": "18.5.0",
    "@react-native-firebase/app": "18.5.0",
    "@react-native-firebase/auth": "18.5.0",
    "@react-native-firebase/crashlytics": "18.5.0",
    "@react-native-firebase/messaging": "18.5.0",
    "@react-native-firebase/remote-config": "18.5.0",
    "@react-navigation/bottom-tabs": "5.11.15",
    "@react-navigation/material-bottom-tabs": "5.3.19",
    "@react-navigation/material-top-tabs": "5.3.19",
    "@react-navigation/native": "5.9.8",
    "@react-navigation/stack": "5.14.9",
    "@reduxjs/toolkit": "1.7.2",
    "@testing-library/react-hooks": "8.0.1",
    "@testing-library/react-native": "10.0.0",
    "@twotalltotems/react-native-otp-input": "1.3.7",
    "axios": "0.19.2",
    "buffer": "5.4.3",
    "colord": "2.9.3",
    "compare-versions": "3.6.0",
    "date-fns": "2.14.0",
    "date-fns-tz": "1.1.4",
    "dayjs": "1.11.9",
    "deprecated-react-native-prop-types": "4.0.0",
    "expo": "48.0.16",
    "expo-av": "13.2.1",
    "expo-image-manipulator": "11.1.1",
    "expo-image-picker": "14.1.1",
    "expo-permissions": "14.1.1",
    "fe-shared-resources": "git+ssh://git@gitlab.com/goss-media/avengers/fe-shared-resources.git#v1.0.7",
    "formik": "2.2.9",
    "fuse.js": "6.6.2",
    "fuzzy-search": "^3.2.1",
    "immer": "5.3.4",
    "instabug-reactnative": "11.13.0",
    "intl": "1.2.5",
    "intl-locales-supported": "1.8.12",
    "jest-date-mock": "1.0.8",
    "lodash.camelcase": "4.3.0",
    "lodash.chunk": "4.2.0",
    "lodash.compact": "3.0.1",
    "lodash.debounce": "4.0.8",
    "lodash.flatten": "4.4.0",
    "lodash.get": "4.4.2",
    "lodash.identity": "3.0.0",
    "lodash.isboolean": "3.0.3",
    "lodash.isfunction": "3.0.9",
    "lodash.isnil": "4.0.0",
    "lodash.isnumber": "3.0.3",
    "lodash.isobject": "3.0.2",
    "lodash.isplainobject": "4.0.6",
    "lodash.isstring": "4.0.1",
    "lodash.isundefined": "3.0.1",
    "lodash.merge": "4.6.2",
    "lodash.omit": "4.5.0",
    "lodash.orderby": "4.6.0",
    "lodash.reverse": "4.0.1",
    "lodash.round": "4.0.4",
    "lodash.set": "4.3.2",
    "lodash.shuffle": "4.2.0",
    "lodash.slice": "4.2.0",
    "lodash.sortby": "4.7.0",
    "lodash.startcase": "4.4.0",
    "lodash.take": "4.1.1",
    "lodash.times": "4.3.2",
    "lodash.tostring": "4.1.4",
    "lodash.truncate": "4.4.2",
    "lodash.union": "4.6.0",
    "lodash.unionby": "4.8.0",
    "lodash.upperfirst": "4.3.1",
    "lodash.without": "4.4.0",
    "mixpanel-react-native": "2.1.0",
    "mock-async-storage": "2.2.0",
    "moti": "0.25.3",
    "postcode-validator": "3.7.0",
    "react": "18.1.0",
    "react-fast-compare": "3.2.2",
    "react-freeze": "1.0.3",
    "react-native": "0.70.6",
    "react-native-appodeal": "3.2.1",
    "react-native-appsflyer": "6.12.2",
    "react-native-auto-size-text": "1.1.1",
    "react-native-blob-util": "0.13.16",
    "react-native-circular-progress": "1.3.8",
    "react-native-confetti-cannon": "1.5.2",
    "react-native-config": "1.4.5",
    "react-native-country-picker-modal": "2.0.0",
    "react-native-device-info": "9.0.2",
    "react-native-dropdown-picker": "5.4.7-beta.1",
    "react-native-dropdownalert": "4.2.1",
    "react-native-extended-stylesheet": "0.12.0",
    "react-native-fast-image": "8.5.11",
    "react-native-fbsdk-next": "12.1.2",
    "react-native-fix-image": "2.1.0",
    "react-native-gesture-handler": "2.9.0",
    "react-native-haptic-feedback": "1.13.1",
    "react-native-iap": "11.0.7",
    "react-native-image-sequence": "0.7.0",
    "react-native-in-app-review": "3.2.2",
    "react-native-indicator": "1.2.2",
    "react-native-keyboard-accessory": "0.1.16",
    "react-native-keyboard-aware-scroll-view": "0.9.5",
    "react-native-linear-gradient": "2.8.3",
    "react-native-localize": "2.1.4",
    "react-native-maskview": "1.1.3",
    "react-native-pager-view": "6.2.0",
    "react-native-paper": "3.5.1",
    "react-native-progress-wheel": "1.0.5",
    "react-native-radial-gradient": "1.1.2",
    "react-native-raw-bottom-sheet": "2.2.0",
    "react-native-reanimated": "3.0.2",
    "react-native-render-html": "6.3.4",
    "react-native-safe-area-context": "3.2.0",
    "react-native-scalable-image": "1.1.0",
    "react-native-screens": "3.20.0",
    "react-native-share": "7.3.0",
    "react-native-snap-carousel": "4.0.0-beta.6",
    "react-native-splash-screen": "3.2.0",
    "react-native-status-bar-height": "2.6.0",
    "react-native-svg": "12.1.1",
    "react-native-swipe-gestures": "^1.0.5",
    "react-native-swiper": "1.6.0",
    "react-native-tab-view": "3.5.2",
    "react-native-toast-message": "2.1.7",
    "react-native-vector-icons": "8.1.0",
    "react-native-version-info": "1.1.0",
    "react-native-view-shot": "3.1.2",
    "react-native-webview": "12.0.2",
    "react-redux": "7.2.2",
    "redux-persist": "6.0.0",
    "redux-persist-filesystem-storage": "4.0.0",
    "rn-android-keyboard-adjust": "2.0.0",
    "rn-redux-mixpanel": "1.3.0",
    "shallow-equal": "1.2.1",
    "yup": "0.32.11"
  },

firebase.json for react-native-firebase v6:

# 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? - [ ] I am using `android/gradle.settings` `jetifier=true` for Android compatibility? - [ ] 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 = "33.0.0" minSdkVersion = 21 compileSdkVersion = 33 targetSdkVersion = 33 kotlinVersion = '1.6.10' if (System.properties['os.arch'] == "aarch64") { // For M1 Users we need to use the NDK 24 which added support for aarch64 ndkVersion = "24.0.8215888" } else { // Otherwise we default to the side-by-side NDK version from AGP. ndkVersion = "21.4.7075529" } firebaseMessagingVersion = "21.1.0" googlePlayServicesVersion = "16.0.0" // default: "+" } repositories { google() mavenCentral() jcenter() } dependencies { classpath("com.android.tools.build:gradle:7.4.2") classpath("com.facebook.react:react-native-gradle-plugin") classpath("de.undercouch:gradle-download-task:5.0.1") classpath 'com.google.gms:google-services:4.4.0' classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1' classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { // mavenCentral() ?? // mavenLocal() ?? maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url(new File(["node", "--print", "require.resolve('react-native/package.json')"].execute().text.trim(), "../android")) } maven { // Android JSC is installed from npm url(new File(["node", "--print", "require.resolve('jsc-android/package.json')"].execute().text.trim(), "../dist")) } mavenCentral { // We don't want to fetch react-native from Maven Central as there are // older versions over there. content { excludeGroup "com.facebook.react" } } maven { // expo-camera bundles a custom com.google.android:cameraview url "$rootDir/../node_modules/expo-camera/android/maven" } maven { url("$rootDir/../node_modules/detox/Detox-android") } google() mavenCentral() maven { url 'https://www.jitpack.io' } jcenter() maven { url "https://artifactory.appodeal.com/appodeal" } } } ``` #### `android/app/build.gradle`: ```groovy apply plugin: "com.android.application" apply plugin: 'com.google.gms.google-services' import com.android.build.OutputFile import org.apache.tools.ant.taskdefs.condition.Os // react-native-config project.ext.envConfigFiles = [ devDebug: ".env", devRelease: ".env", stgDebug: ".env.staging", stgRelease: ".env.staging", preDebug: ".env.prerelease", preRelease: ".env.prerelease", prodDebug: ".env.production", prodRelease: ".env.production", ] apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle" apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.firebase.crashlytics' 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 * 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 nodeExecutableAndArgs: ["node", "--max-old-space-size=8192"], bundleInDebug: true ] apply from: "../../node_modules/react-native/react.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-intl:+' /** * 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", true); /** * Architectures to build native code for. */ def reactNativeArchitectures() { // def value = project.getProperties().get("reactNativeArchitectures") // return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] return ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] } android { ndkVersion rootProject.ext.ndkVersion compileSdkVersion rootProject.ext.compileSdkVersion defaultConfig { configurations.all { resolutionStrategy { force 'androidx.sqlite:sqlite-framework:2.1.0' } } applicationId "com.goss" applicationIdSuffix "" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 2411 versionName "7.59.0" multiDexEnabled true resValue "string", "build_config_package", "com.goss" missingDimensionStrategy 'store', 'play' testBuildType System.getProperty('testBuildType', 'debug') testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() if (isNewArchitectureEnabled()) { // We configure the NDK build only if you decide to opt-in for the New Architecture. externalNativeBuild { cmake { arguments "-DPROJECT_BUILD_DIR=$buildDir", "-DREACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid", "-DREACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build", "-DNODE_MODULES_DIR=$rootDir/../node_modules", "-DANDROID_STL=c++_shared" } } if (!enableSeparateBuildPerCPUArchitecture) { ndk { abiFilters (*reactNativeArchitectures()) } } } } if (isNewArchitectureEnabled()) { // We configure the NDK build only if you decide to opt-in for the New Architecture. externalNativeBuild { cmake { path "$projectDir/src/main/jni/CMakeLists.txt" } } def reactAndroidProjectDir = project(':ReactAndroid').projectDir def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) { dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck") from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib") into("$buildDir/react-ndk/exported") } def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) { dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck") from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib") into("$buildDir/react-ndk/exported") } afterEvaluate { // If you wish to add a custom TurboModule or component locally, // you should uncomment this line. // preBuild.dependsOn("generateCodegenArtifactsFromSchema") preDebugBuild.dependsOn(packageReactNdkDebugLibs) preReleaseBuild.dependsOn(packageReactNdkReleaseLibs) // Due to a bug inside AGP, we have to explicitly set a dependency // between configureCMakeDebug* tasks and the preBuild tasks. // This can be removed once this is solved: https://issuetracker.google.com/issues/207403732 configureCMakeRelWithDebInfo.dependsOn(preReleaseBuild) configureCMakeDebug.dependsOn(preDebugBuild) reactNativeArchitectures().each { architecture -> tasks.findByName("configureCMakeDebug[${architecture}]")?.configure { dependsOn("preDebugBuild") } tasks.findByName("configureCMakeRelWithDebInfo[${architecture}]")?.configure { dependsOn("preReleaseBuild") } } } } splits { abi { reset() enable enableSeparateBuildPerCPUArchitecture universalApk false // If true, also generate a universal APK include (*reactNativeArchitectures()) } } flavorDimensions "environment" productFlavors { dev { dimension "environment" applicationId "com.goss.debug" resValue "string", "app_name", "goss dev" resValue "string", "url_scheme", "gossappdev" } stg { dimension "environment" applicationId "com.goss.staging" resValue "string", "app_name", "goss stg" resValue "string", "url_scheme", "gossappdev" } pre { dimension "environment" applicationId "com.goss.prerelease" resValue "string", "app_name", "goss pre" resValue "string", "url_scheme", "gossapp" } prod { dimension "environment" applicationId "com.goss" resValue "string", "app_name", "goss" resValue "string", "url_scheme", "gossapp" } } signingConfigs { debug { storeFile file('debug.keystore') storePassword 'android' keyAlias 'androiddebugkey' keyPassword 'android' } release { storeFile file('release.keystore') storePassword 'GossApp' keyAlias 'AliasKey' keyPassword 'GossApp' } } buildTypes { debug { signingConfig signingConfigs.debug } release { // Caution! In production, you need to generate your own keystore file. // see https://reactnative.dev/docs/signed-apk-android. signingConfig signingConfigs.release minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro" } } // 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 = defaultConfig.versionCode * 1000 + versionCodes.get(abi) } } } } dependencies { androidTestImplementation('com.wix:detox:+') implementation fileTree(dir: "libs", include: ["*.jar"]) //noinspection GradleDynamicVersion 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' exclude group:'com.squareup.okhttp3', module:'okhttp' } debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") { exclude group:'com.facebook.flipper' } implementation "com.facebook.react:react-native:+" // From node_modules implementation 'com.facebook.android:facebook-login:4.30.0' implementation('com.facebook.soloader:soloader:0.10.4+') { because('https://github.com/facebook/react-native/issues/29528#issuecomment-737734746') } implementation(project(":instabug-reactnative")){ exclude group: 'com.google.android.play', module: 'core-common' exclude group: 'com.google.android.play', module: 'review' because('https://github.com/Instabug/Instabug-React-Native/issues/971') } // appodeal implementation ('com.appodeal.ads:sdk:3.2.0.+') { exclude group: 'com.appodeal.ads.sdk.services', module: 'adjust' exclude group: 'com.appodeal.ads.sdk.services', module: 'appsflyer' exclude group: 'com.appodeal.ads.sdk.services', module: 'firebase' exclude group: 'com.appodeal.ads.sdk.services', module: 'facebook_analytics' exclude group: 'com.appodeal.ads.sdk.services', module: 'stack_analytics' } implementation 'com.android.support:multidex:1.0.3' implementation project(':react-native-splash-screen') def isGifEnabled = (findProperty('expo.gif.enabled') ?: "") == "true"; def isWebpEnabled = (findProperty('expo.webp.enabled') ?: "") == "true"; def isWebpAnimatedEnabled = (findProperty('expo.webp.animated') ?: "") == "true"; implementation('androidx.work:work-runtime-ktx:2.8.0-alpha01') { because('https://github.com/react-native-maps/react-native-maps/issues/4083#issue-1119280606') } // If your app supports Android versions before Ice Cream Sandwich (API level 14) // All fresco packages should use the same version if (isGifEnabled || isWebpEnabled) { implementation 'com.facebook.fresco:fresco:2.0.0' implementation 'com.facebook.fresco:imagepipeline-okhttp3:2.0.0' } if (isGifEnabled) { // For animated gif support implementation 'com.facebook.fresco:animated-gif:2.0.0' } if (isWebpEnabled) { // For webp support implementation 'com.facebook.fresco:webpsupport:2.0.0' if (isWebpAnimatedEnabled) { // Animated webp support implementation 'com.facebook.fresco:animated-webp:2.0.0' } } // For animated GIF support implementation "com.facebook.fresco:animated-base-support:1.3.0" implementation "com.facebook.fresco:animated-gif:2.0.0" // react-native-screens implementation 'androidx.appcompat:appcompat:1.1.0-rc01' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02' implementation "androidx.browser:browser:1.3.0" if (enableHermes) { // noinspection GradleDynamicVersion implementation("com.facebook.react:hermes-engine:+") { // From node_modules exclude group:'com.facebook.fbjni' } } else { implementation jscFlavor } } if (isNewArchitectureEnabled()) { // If new architecture is enabled, we let you build RN from source // Otherwise we fallback to a prebuilt .aar bundled in the NPM package. // This will be applied to all the imported transtitive dependency. configurations.all { resolutionStrategy.dependencySubstitution { substitute(module("com.facebook.react:react-native")) .using(project(":ReactAndroid")) .because("On New Architecture we're building React Native from source") substitute(module("com.facebook.react:hermes-engine")) .using(project(":ReactAndroid:hermes-engine")) .because("On New Architecture we're building Hermes from source") } } } // 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.implementation into 'libs' } apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) def isNewArchitectureEnabled() { return false // To opt-in for the New Architecture, you can either: // - Set `newArchEnabled` to true inside the `gradle.properties` file // - Invoke gradle with `-newArchEnabled=true` // - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true` // return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true" } ``` #### `android/settings.gradle`: ```groovy include ':rn-android-keyboard-adjust' project(':rn-android-keyboard-adjust').projectDir = new File(rootProject.projectDir, '../node_modules/rn-android-keyboard-adjust/android') include ':react-native-haptic-feedback' project(':react-native-haptic-feedback').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-haptic-feedback/android') include ':@react-native-community_netinfo' project(':@react-native-community_netinfo').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/netinfo/android') include ':react-native-splash-screen' project(':react-native-splash-screen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-splash-screen/android') apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json')"].execute().text.trim(), "../native_modules.gradle"); apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) include ':app' apply from: new File(["node", "--print", "require.resolve('expo/package.json')"].execute().text.trim(), "../scripts/autolinking.gradle") useExpoModules() includeBuild('../node_modules/react-native-gradle-plugin') if (settings.hasProperty("newArchEnabled") && settings.newArchEnabled == "true") { include(":ReactAndroid") project(":ReactAndroid").projectDir = file('../node_modules/react-native/ReactAndroid') include(":ReactAndroid:hermes-engine") project(":ReactAndroid:hermes-engine").projectDir = file('../node_modules/react-native/ReactAndroid/hermes-engine') } ``` #### `MainApplication.java`: ```java package com.goss; import expo.modules.ApplicationLifecycleDispatcher; import expo.modules.ReactNativeHostWrapper; import android.app.Application; import android.content.Context; import android.content.res.Configuration; import androidx.annotation.NonNull; import com.facebook.react.PackageList; import com.facebook.react.ReactInstanceManager; import com.facebook.react.ReactApplication; import com.tclado.androidkeyboardadjust.AndroidKeyboardAdjustPackage; import com.mkuczera.RNReactNativeHapticFeedbackPackage; import com.reactnativecommunity.netinfo.NetInfoPackage; import org.devio.rn.splashscreen.SplashScreenReactPackage; import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; import com.facebook.react.config.ReactFeatureFlags; import com.facebook.FacebookSdk; import com.goss.newarchitecture.MainApplicationReactNativeHost; import expo.modules.ApplicationLifecycleDispatcher; import expo.modules.ReactNativeHostWrapper; import com.facebook.soloader.SoLoader; import java.lang.reflect.InvocationTargetException; import java.util.List; import android.database.CursorWindow; import java.lang.reflect.Field; public class MainApplication extends Application implements ReactApplication { private final ReactNativeHost mReactNativeHost = new ReactNativeHostWrapper(this, 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"; } }); private final ReactNativeHost mNewArchitectureNativeHost = new MainApplicationReactNativeHost(this); @Override public ReactNativeHost getReactNativeHost() { if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { return mNewArchitectureNativeHost; } else { return mReactNativeHost; } } @Override public void onCreate() { super.onCreate(); try { Field field = CursorWindow.class.getDeclaredField("sCursorWindowSize"); field.setAccessible(true); field.set(null, 100 * 1024 * 1024); // the 100MB is the new size } catch (Exception e) { e.printStackTrace(); } // If you opted-in for the New Architecture, we enable the TurboModule system ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; SoLoader.init(this, /* native exopackage */ false); initializeFlipper(this, getReactNativeHost().getReactInstanceManager());// Remove this line if you don't want Flipper enabled // expo ApplicationLifecycleDispatcher.onApplicationCreate(this); } /** * Loads Flipper in React Native templates. * * @param context */ 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.goss.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(); } } } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); ApplicationLifecycleDispatcher.onConfigurationChanged(this, newConfig); } } ``` #### `AndroidManifest.xml`: ```xml ```


Environment

Click To Expand

**`react-native info` output:** ``` System: OS: macOS 14.2.1 CPU: (8) arm64 Apple M1 Pro Memory: 111.59 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node Yarn: 1.22.18 - ~/.nvm/versions/node/v16.15.0/bin/yarn npm: 8.5.5 - ~/.nvm/versions/node/v16.15.0/bin/npm Watchman: Not Found Managers: CocoaPods: Not Found SDKs: iOS SDK: Platforms: DriverKit 23.2, iOS 17.2, macOS 14.2, tvOS 17.2, watchOS 10.2 Android SDK: Not Found IDEs: Android Studio: 2021.1 AI-211.7628.21.2111.8309675 Xcode: 15.1/15C65 - /usr/bin/xcodebuild Languages: Java: 11.0.15 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.1.0 => 18.1.0 react-native: 0.70.6 => 0.70.6 react-native-macos: 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 - [ ] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** 18.5.0 - **`Firebase` module(s) you're using that has the issue:** "@react-native-firebase/analytics": "18.5.0", "@react-native-firebase/app": "18.5.0", "@react-native-firebase/auth": "18.5.0", "@react-native-firebase/crashlytics": "18.5.0", "@react-native-firebase/messaging": "18.5.0", "@react-native-firebase/remote-config": "18.5.0", - **Are you using `TypeScript`?** - `Y` & `4.7.4`


trickeyd commented 10 months ago

Hey - just wondering if more info is needed form my side. The issue is mostly fixed with the changes mentioned above, crashlitics report that loads are still failing sometimes on prod, so I really want to get to the bottom of it. Not to mention how ugly it is to have a platform specific fix here.

Any help would be greatly appreciated.

mikehardy commented 9 months ago

I think this is an API misunderstanding and my working hypothesis is that it is working as designed.

1- fetch will fetch new values if they have not been fetched before the cache timeout which defaults to 12 hours - https://rnfirebase.io/remote-config/usage#caching

So, likely, you may be updating remote-config values but they are simply not being fetched because the local cache is still determined to be valid. If you manually do a reset, of course you destroy the local cache so you will fetch new values.

That means that your workaround appears to work, but it is likely just that what you want is either

You can play with this idea by examining the source of the remote-config param value before you fetch, and after you fetch initially, and after you fetch again (when it should be cached) - https://rnfirebase.io/remote-config/usage#value-source

2- you are using the activate API but assigning it to the value "configsWereRetrieved" - that implies a misunderstanding of what fetch is doing and what activate is doing.

So I would expect it to return false almost all the time.

Your code appears correct. The module appears to be working. I think you're just running up against caching and you have an avenue to examine that with a look at the value sources. real-time config updates are available for use cases where you need faster updates