Skip to content

[πŸ›] πŸ”₯ Crash on Android release app when calling messaging().onMessage()Β #8622

@artemkhalygov

Description

@artemkhalygov

Issue

I’m experiencing a crash on Android when using @react-native-firebase/messaging on release build. For development build everything works as expected

When I received a push notification while the app was in the foreground, it crashed.

The crash occurs even if I just invoke messaging().onMessage() without providing a callback.

import messaging from '@react-native-firebase/messaging'

useEffect(() => {
    const unsubscribe = messaging().onMessage(async remoteMessage => {
      
    })

    return () => {
      unsubscribe()
    }
  }, [])

The following error appears in Logcat when the app crashes:

FATAL EXCEPTION: mqt_native_modules
Process: com.*..*.dev, PID: 7393

com.facebook.react.common.JavascriptException: 
Error: Exception in HostFunction: Could not enqueue microtask because they are disabled in this runtime, js engine: hermes

Stack:
  setImmediate@1:248808
  anonymous@1:1096413
  loadModuleImplementation@1:65952
  guardedLoadModule@1:65476
  metroRequire@1:65106
  anonymous@1:72563
  loadModuleImplementation@1:65952
  guardedLoadModule@1:65433
  metroRequire@1:65106
  global@1:64634

    at com.facebook.react.modules.core.ExceptionsManagerModule.reportException(ExceptionsManagerModule.kt:52)
    at com.facebook.jni.NativeRunnable.run(Native Method)
    at android.os.Handler.handleCallback(Handler.java:959)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
    at android.os.Looper.loopOnce(Looper.java:257)
    at android.os.Looper.loop(Looper.java:342)
    at com.facebook.react.bridge.queue.MessageQueueThreadImpl.lambda$startNewBackgroundThread$2(MessageQueueThreadImpl.java:217)
    at com.facebook.react.bridge.queue.MessageQueueThreadImpl$$ExternalSyntheticLambda1.run(D8$$SyntheticClass:0)
    at java.lang.Thread.run(Thread.java:1119)

Project Files

Javascript

Click To Expand

package.json:

{
  "name": "driver",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "android": "yarn android:dev",
    "android:dev": "react-native run-android --mode=devdebug --appIdSuffix=dev",
    "android:staging": "react-native run-android --mode=stagingdebug --appIdSuffix=staging",
    "android:prod": "react-native run-android --mode=proddebug",
    "ios": "yarn ios:dev",
    "ios:dev": "react-native run-ios --scheme \"DebugDev\" --configuration \"Debug\"",
    "ios:staging": "react-native run-ios --scheme \"DebugStage\" --configuration \"Debug\"",
    "ios:prod": "react-native run-ios --scheme \"DebugProd\" --configuration \"Debug\"",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint .",
    "flow": "flow",
    "collect-translations": "node makeTranslations.mjs"
  },
  "dependencies": {
    "@gorhom/bottom-sheet": "^5.1.2",
    "@react-native-async-storage/async-storage": "^1.17.10",
    "@react-native-community/cli": "15.0.1",
    "@react-native-community/cli-platform-android": "15.0.1",
    "@react-native-community/cli-platform-ios": "15.0.1",
    "@react-native-community/geolocation": "^3.4.0",
    "@react-native-community/push-notification-ios": "^1.11.0",
    "@react-native-firebase/app": "^21.14.0",
    "@react-native-firebase/messaging": "^21.14.0",
    "@react-navigation/bottom-tabs": "^6.4.0",
    "@react-navigation/native": "^6.0.13",
    "@react-navigation/stack": "^6.3.2",
    "@supersami/rn-foreground-service": "^2.2.0",
    "@tanstack/react-query": "^4.9.0",
    "axios": "^0.27.2",
    "base-64": "^1.0.0",
    "dayjs": "1.11.5",
    "formik": "^2.2.9",
    "hermes-eslint": "^0.29.1",
    "intl-pluralrules": "^1.3.1",
    "jwt-decode": "^3.1.2",
    "opening_hours": "^3.8.0",
    "qs": "^6.14.0",
    "react": "19.0.0",
    "react-native": "0.78.3",
    "react-native-background-actions": "^4.0.1",
    "react-native-click-outside": "^0.1.1",
    "react-native-config": "^1.5.1",
    "react-native-device-info": "^14.0.4",
    "react-native-dropdown-picker": "^5.4.4",
    "react-native-gesture-handler": "^2.26.0",
    "react-native-image-picker": "^7.1.2",
    "react-native-linear-gradient": "^2.8.3",
    "react-native-maps": "^1.3.2",
    "react-native-parsed-text": "^0.0.22",
    "react-native-permissions": "^5.1.0",
    "react-native-push-notification": "^8.1.1",
    "react-native-reanimated": "3.17.1",
    "react-native-safe-area-context": "^5.5.2",
    "react-native-splash-screen": "^3.3.0",
    "react-native-vector-icons": "^9.2.0",
    "rn-fetch-blob": "0.13.0-beta.2",
    "sp-react-native-in-app-updates": "^1.3.1",
    "yup": "^0.32.11"
  },
  "devDependencies": {
    "@babel/core": "^7.25.2",
    "@babel/preset-env": "^7.25.3",
    "@babel/runtime": "^7.25.0",
    "@react-native-community/eslint-config": "^2.0.0",
    "@react-native/babel-preset": "0.78.3",
    "@react-native/eslint-config": "0.78.3",
    "@react-native/metro-config": "0.78.3",
    "@react-native/typescript-config": "0.78.3",
    "@types/jest": "^29.5.13",
    "@types/react": "^19.0.0",
    "@types/react-test-renderer": "^19.0.0",
    "babel-jest": "^29.6.3",
    "babel-plugin-module-resolver": "^4.1.0",
    "commander": "^9.4.1",
    "common": "^0.2.5",
    "eslint": "^8.19.0",
    "eslint-import-resolver-babel-module": "^5.3.1",
    "eslint-plugin-ft-flow": "^3.0.3",
    "eslint-plugin-import": "^2.26.0",
    "flow-bin": "0.182",
    "glob": "^8.0.3",
    "jest": "^29.6.3",
    "metro-react-native-babel-preset": "^0.72.1",
    "prettier": "2.8.8",
    "react-native-screens": "^4.8.0",
    "react-test-renderer": "19.0.0",
    "reactotron-react-native": "^5.1.8"
  },
  "jest": {
    "preset": "react-native"
  },
  "engines": {
    "node": ">=18"
  }
}

firebase.json for react-native-firebase v6:

# N/A

Android

Click To Expand

Have you converted to AndroidX?

  • 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:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "35.0.0"
        minSdkVersion = 24
        compileSdkVersion = 35
        targetSdkVersion = 35
        ndkVersion = "27.1.12297006"
        kotlinVersion = "2.0.21"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
        classpath 'com.google.gms:google-services:4.4.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

apply plugin: "com.facebook.react.rootproject"

android/app/build.gradle:

apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"

project.ext.envConfigFiles = [
    devdebug: ".env.dev",
    devrelease: ".env.dev",
    stagingdebug: ".env.staging",
    stagingrelease: ".env.staging",
    proddebug: ".env.prod",
    prodrelease: ".env.prod"
]

apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
/**
 * This is the configuration block to customize your React Native Android app.
 * By default you don't need to apply any configuration, just uncomment the lines you need.
 */
react {
    /* Folders */
    //   The root of your project, i.e. where "package.json" lives. Default is '..'
    // root = file("../")
    //   The folder where the react-native NPM package is. Default is ../node_modules/react-native
    // reactNativeDir = file("../node_modules/react-native")
    //   The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen
    // codegenDir = file("../node_modules/@react-native/codegen")
    //   The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
    // cliFile = file("../node_modules/react-native/cli.js")

    /* Variants */
    //   The list of variants to that are debuggable. For those we're going to
    //   skip the bundling of the JS bundle and the assets. By default is just 'debug'.
    //   If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
    // debuggableVariants = ["liteDebug", "prodDebug"]

    /* Bundling */
    //   A list containing the node command and its flags. Default is just 'node'.
    // nodeExecutableAndArgs = ["node"]
    //
    //   The command to run when bundling. By default is 'bundle'
    // bundleCommand = "ram-bundle"
    //
    //   The path to the CLI configuration file. Default is empty.
    // bundleConfig = file(../rn-cli.config.js)
    //
    //   The name of the generated asset file containing your JS bundle
    // bundleAssetName = "MyApplication.android.bundle"
    //
    //   The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
    // entryFile = file("../js/MyApplication.android.js")
    //
    //   A list of extra flags to pass to the 'bundle' commands.
    //   See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
    // extraPackagerArgs = []

    /* Hermes Commands */
    //   The hermes compiler command to run. By default it is 'hermesc'
    // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
    //
    //   The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
    // hermesFlags = ["-O", "-output-source-map"]

    /* Autolinking */
    autolinkLibrariesWithApp()
}

/**
 * Set this to true to Run Proguard on Release builds to minify the Java bytecode.
 */
def enableProguardInReleaseBuilds = false

/**
 * The preferred build flavor of JavaScriptCore.
 *
 * For example, to use the international variant, you can use:
 * `def jscFlavor = 'io.github.react-native-community:jsc-android:2026004.+'`
 *
 * 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 = 'io.github.react-native-community:jsc-android:2026004.+'

android {
    ndkVersion rootProject.ext.ndkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
    compileSdk rootProject.ext.compileSdkVersion

    namespace "driver"

    defaultConfig {
        applicationId "driver"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "0.1.0"
        resValue "string", "build_config_package", "driver"
    }

    kotlinOptions {
      freeCompilerArgs += ["-Xskip-metadata-version-check"]
    }

    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
            matchingFallbacks = ['debug', 'release']
        }
        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"
        }
    }

    flavorDimensions "env"
    productFlavors {
        dev {
            resValue "string", "app_name", "iCans Dev"
            applicationIdSuffix ".dev"
            versionCode 19
            versionName "1.2.4.dev"
        }
        staging {
            resValue "string", "app_name", "iCans Staging"
            applicationIdSuffix ".staging"
            versionCode 19
            versionName "1.2.4.staging"
        }
        prod {
            resValue "string", "app_name", "iCans Driver"
            versionCode 19
            versionName "1.2.4"
        }
    }

    // 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
            // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
            def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(com.android.build.OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        defaultConfig.versionCode * 1000 + versionCodes.get(abi)
            }

        }
    }
}

dependencies {
    // The version of react-native is set by the React Native Gradle Plugin
    implementation("com.facebook.react:react-android")
    // Import the Firebase BoM
    implementation(platform("com.google.firebase:firebase-bom:33.1.1"))
    implementation project(':react-native-push-notification')
    implementation project(':react-native-permissions')


    if (hermesEnabled.toBoolean()) {
        implementation("com.facebook.react:hermes-android")
    } else {
        implementation jscFlavor
    }
}

android/settings.gradle:

pluginManagement { includeBuild("../node_modules/@react-native/gradle-plugin") }
plugins { id("com.facebook.react.settings") }
extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() }
rootProject.name = 'mobitron'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
includeBuild('../node_modules/@react-native/gradle-plugin')

include ':react-native-permissions'
project(':react-native-permissions').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-permissions/android')

MainApplication.kt:

package com.ironcans.ICANSDriver
 
import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
import com.facebook.react.defaults.DefaultReactActivityDelegate
import android.os.Bundle;

class MainActivity : ReactActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(null)
  }

  /**
   * Returns the name of the main component registered from JavaScript. This is used to schedule
   * rendering of the component.
   */
  override fun getMainComponentName(): String = "ICANSDriver"
 
  /**
   * Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate]
   * which allows you to enable New Architecture with a single boolean flags [fabricEnabled]
   */
  override fun createReactActivityDelegate(): ReactActivityDelegate =
      DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)
}

AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="driver">

    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION"/>
    <uses-permission android:name="android.permission.WAKE_LOCK" />


    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme"
      android:supportsRtl="true">

      <service android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask" android:foregroundServiceType="dataSync" />

      <!-- Change the value to true to enable pop-up for in foreground on receiving remote notifications (for prevent duplicating while showing local notifications set this to false) -->
      <meta-data  android:name="com.dieam.reactnativepushnotification.notification_foreground"
                  android:value="false"/>
      <!-- Change the resource name to your App's accent color - or any other color you want -->
      <meta-data  android:name="com.dieam.reactnativepushnotification.notification_color"
                  android:resource="@color/primary_light"/> <!-- or @android:color/{name} to use a standard color -->

      <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions" android:exported="false" />
      <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
      <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver" android:exported="false">
          <intent-filter>
              <action android:name="android.intent.action.BOOT_COMPLETED" />
              <action android:name="android.intent.action.QUICKBOOT_POWERON" />
              <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
          </intent-filter>
      </receiver>

      <service
          android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
          android:exported="false" >
          <intent-filter>
              <action android:name="com.google.firebase.MESSAGING_EVENT" />
          </intent-filter>
      </service>
      <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/GOOGLE_MAPS_API_KEY_ANDROID"/>
      <meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@drawable/ic_notification_icon" />
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
        android:launchMode="singleTask"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustPan"
        android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter android:label="filter_react_native">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="icansdriver" />
            </intent-filter>
      </activity>
    </application>
</manifest>


Environment

Click To Expand


**`react-native info` output:**

System:
  OS: macOS 15.5
  CPU: (14) arm64 Apple M4 Pro
  Memory: 506.08 MB / 48.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.19.3
    path: ~/.nvm/versions/node/v20.19.3/bin/node
  Yarn:
    version: 1.22.22
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.8.2
    path: ~/.nvm/versions/node/v20.19.3/bin/npm
  Watchman:
    version: 2025.03.10.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.2
      - iOS 18.2
      - macOS 15.2
      - tvOS 18.2
      - visionOS 2.2
      - watchOS 11.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2025.1 AI-251.25410.109.2511.13665796
  Xcode:
    version: 16.2/16C5032a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.14
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.1
    wanted: 15.0.1
  react:
    installed: 19.0.0
    wanted: 19.0.0
  react-native:
    installed: 0.78.3
    wanted: 0.78.3
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: false
  newArchEnabled: true
  • Platform that you're experiencing the issue on:
    • iOS
    • 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:
    • 21.14.0
  • Firebase module(s) you're using that has the issue:
    • @react-native-firebase/messaging
  • Are you using TypeScript?
    • N


Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions