react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

[🐛] 🔥 @react-native-firebase/messaging giving SERVICE_NOT_AVAILABLE error

Open sanaf1333 opened this issue 1 year ago • 4 comments

Issue

I am using @react-native-firebase/messaging for push notifications, but getting this error when getting token FCM Error: NativeFirebaseError: [messaging/unknown] java.io.IOException: java.util.concurrent.ExecutionException: java.io.IOException: SERVICE_NOT_AVAILABLE. It worked for a split second and returned toke on same emulator but then again started throwing this error, I have also added timer in case the messaging isn't available instantly but unfortunately this didn't fix the issue. I am using following versions

"@react-native-firebase/app": "^21.14.0",
    "@react-native-firebase/messaging": "^21.14.0",

I have also tried degrading to

"@react-native-firebase/app": "^21.12.0",
    "@react-native-firebase/messaging": "^21.12.0",

I have added this in AndroidManifest.xml

<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/ic_large_icon"/>
      <meta-data android:name="com.notifee.react.native.notification_icon" android:resource="@drawable/ic_large_icon"/>

I have added this in android/app/build.gradle

apply plugin: 'com.google.gms.google-services'
dependencies {
implementation "com.google.firebase:firebase-messaging:23.4.1"
}

Also added this in android/build.gradle classpath 'com.google.gms:google-services:4.4.2' This is my react-native version "react-native": "0.79.1", I have tried on both real device and emulator but its not working.

Describe your issue here


Project Files

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.2'
    }
}

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

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

react {
    /* Folders */
    
    autolinkLibrariesWithApp()
}

def enableProguardInReleaseBuilds = false

def jscFlavor = 'io.github.react-native-community:jsc-android:2026004.+'

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

    namespace "com.twin.investorMobileApp"
    defaultConfig {
        applicationId "com.twin.investorMobileApp"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
    }
    signingConfigs {
        debug {
            storeFile file('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://reactnative.dev/docs/signed-apk-android.
            signingConfig signingConfigs.debug
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
}

dependencies {
    // The version of react-native is set by the React Native Gradle Plugin
    implementation("com.facebook.react:react-android")
    implementation "com.google.firebase:firebase-messaging:23.4.1"

    if (hermesEnabled.toBoolean()) {
        implementation("com.facebook.react:hermes-android")
    } else {
        implementation jscFlavor
    }
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

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

    <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">
      <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/ic_large_icon"/>
      <meta-data android:name="com.notifee.react.native.notification_icon" android:resource="@drawable/ic_large_icon"/>
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <service
          android:name=".java.MyFirebaseMessagingService"
          android:exported="false">
          <intent-filter>
              <action android:name="com.google.firebase.MESSAGING_EVENT" />
          </intent-filter>
      </service>
    </application>
    <queries>
      <intent>
        <action android:name="android.intent.action.VIEW" />
        <data android:mimeType="*/*" />
      </intent>
    </queries>
</manifest>

Javascript

Click To Expand

package.json:

{
  "name": "investor-portal-mobile",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest",
    "build:android-stage": "react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res && cd android && ./gradlew clean && ./gradlew assembleDebug"
  },
  "dependencies": {
    "@expo/html-elements": "^0.4.2",
    "@gluestack-ui/accordion": "^1.0.14",
    "@gluestack-ui/actionsheet": "^0.2.53",
    "@gluestack-ui/alert-dialog": "^0.1.38",
    "@gluestack-ui/button": "^1.0.14",
    "@gluestack-ui/checkbox": "^0.1.39",
    "@gluestack-ui/divider": "^0.1.10",
    "@gluestack-ui/form-control": "^0.1.19",
    "@gluestack-ui/icon": "^0.1.27",
    "@gluestack-ui/input": "^0.1.38",
    "@gluestack-ui/link": "^0.1.29",
    "@gluestack-ui/menu": "^0.2.43",
    "@gluestack-ui/modal": "^0.1.41",
    "@gluestack-ui/nativewind-utils": "^1.0.26",
    "@gluestack-ui/overlay": "^0.1.22",
    "@gluestack-ui/popover": "^0.1.49",
    "@gluestack-ui/pressable": "^0.1.23",
    "@gluestack-ui/progress": "^0.1.18",
    "@gluestack-ui/radio": "^0.1.40",
    "@gluestack-ui/select": "^0.1.31",
    "@gluestack-ui/switch": "^0.1.29",
    "@gluestack-ui/textarea": "^0.1.25",
    "@gluestack-ui/toast": "^1.0.9",
    "@legendapp/motion": "^2.4.0",
    "@notifee/react-native": "^9.1.8",
    "@ptomasroos/react-native-multi-slider": "^2.2.2",
    "@react-native-async-storage/async-storage": "^2.1.2",
    "@react-native-community/datetimepicker": "^8.3.0",
    "@react-native-documents/picker": "^10.1.2",
    "@react-native-firebase/app": "^21.12.0",
    "@react-native-firebase/messaging": "^21.12.0",
    "@react-navigation/bottom-tabs": "^7.3.10",
    "@react-navigation/native": "^7.1.6",
    "@react-navigation/native-stack": "^7.3.10",
    "@react-navigation/stack": "^7.2.10",
    "@tanstack/react-query": "^5.74.3",
    "axios": "^1.8.4",
    "countries-list": "^3.1.1",
    "nativewind": "^4.1.23",
    "react": "19.0.0",
    "react-dom": "^19.1.0",
    "react-hook-form": "^7.55.0",
    "react-native": "0.79.1",
    "react-native-biometrics": "^3.0.1",
    "react-native-css-interop": "^0.1.22",
    "react-native-dotenv": "^3.4.11",
    "react-native-file-viewer": "^2.1.5",
    "react-native-fs": "^2.20.0",
    "react-native-gesture-handler": "^2.25.0",
    "react-native-get-random-values": "^1.11.0",
    "react-native-gifted-charts": "^1.4.60",
    "react-native-google-places-autocomplete": "^2.5.7",
    "react-native-keyboard-aware-scroll-view": "^0.9.5",
    "react-native-linear-gradient": "^2.8.3",
    "react-native-mmkv": "^3.2.0",
    "react-native-permissions": "^5.3.0",
    "react-native-plaid-link-sdk": "^12.1.1",
    "react-native-reanimated": "^3.17.4",
    "react-native-reanimated-carousel": "^4.0.2",
    "react-native-safe-area-context": "^5.4.0",
    "react-native-screens": "^4.10.0",
    "react-native-share": "^12.0.9",
    "react-native-svg": "^15.11.2",
    "react-native-url-polyfill": "^2.0.0",
    "react-native-vector-icons": "^10.2.0",
    "react-native-webview": "^13.13.5",
    "tailwindcss": "^3.4.17"
  },
  "devDependencies": {
    "@babel/core": "^7.25.2",
    "@babel/preset-env": "^7.25.3",
    "@babel/runtime": "^7.25.0",
    "@react-native-community/cli": "18.0.0",
    "@react-native-community/cli-platform-android": "18.0.0",
    "@react-native-community/cli-platform-ios": "18.0.0",
    "@react-native/babel-preset": "0.79.1",
    "@react-native/eslint-config": "0.79.1",
    "@react-native/metro-config": "0.79.1",
    "@react-native/typescript-config": "0.79.1",
    "@types/jest": "^29.5.13",
    "@types/react": "^19.0.0",
    "@types/react-test-renderer": "^19.0.0",
    "babel-plugin-module-resolver": "^5.0.2",
    "eslint": "^8.19.0",
    "jest": "^29.6.3",
    "jscodeshift": "^0.15.2",
    "prettier": "2.8.8",
    "react-test-renderer": "19.0.0",
    "typescript": "5.0.4"
  },
  "engines": {
    "node": ">=18"
  }
}

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:
# N/A

AppDelegate.m:

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

// N/A

android/app/build.gradle:

// N/A

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 = 'namehere'
include ':app'
includeBuild('../node_modules/@react-native/gradle-plugin')

Environment

Click To Expand

react-native info output:

System:
  OS: macOS 15.0.1
  CPU: (12) arm64 Apple M2 Pro
  Memory: 123.61 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 22.1.0
    path: ~/.nvm/versions/node/v22.1.0/bin/node
  Yarn:
    version: 1.22.22
    path: ~/.nvm/versions/node/v22.1.0/bin/yarn
  npm:
    version: 10.8.2
    path: ~/.nvm/versions/node/v22.1.0/bin/npm
  Watchman:
    version: 2025.02.17.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.0
      - iOS 18.0
      - macOS 15.0
      - tvOS 18.0
      - visionOS 2.0
      - watchOS 11.0
  Android SDK:
    API Levels:
      - "31"
      - "34"
      - "35"
    Build Tools:
      - 33.0.1
      - 34.0.0
      - 35.0.0
    System Images:
      - android-35 | Google Play ARM 64 v8a
      - android-35 | Pre-Release 16 KB Page Size Google APIs ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2024.1 AI-241.15989.150.2411.11948838
  Xcode:
    version: 16.0/16A242d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.11
    path: /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 18.0.0
    wanted: 18.0.0
  react:
    installed: 19.0.0
    wanted: 19.0.0
  react-native:
    installed: 0.79.1
    wanted: 0.79.1
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true
  • 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:
    • "@react-native-firebase/messaging": "^21.14.0",
  • Firebase module(s) you're using that has the issue:
    • @react-native-firebase/messaging
  • Are you using TypeScript?
    • Y & 5.0.4

sanaf1333 avatar Apr 24 '25 14:04 sanaf1333

Hi there, this issue has happened to users before and there are a few things to check, this issue could be happening due to (mentioned in this thread: https://github.com/firebase/firebase-android-sdk/issues/4053#issuecomment-1235310551):

  • The phone is offline.
  • The phone is online but it cannot reach Google servers.
  • The firebase messaging servers are temporary unavailable.
  • Google Play services is in an extremely bad state. So I think it is important to double check your Google Services File and ensure everything is correct.

Here is another thread from React Native Firebase for when this issue occured in the past here with possible solutions: https://github.com/invertase/react-native-firebase/issues/2285

I would also like to ask you what devices you are using to test this.

MichaelVerdon avatar Apr 28 '25 05:04 MichaelVerdon

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 attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar May 26 '25 06:05 github-actions[bot]

I am facing this issue from Android < 11, usually in low API level devices API 29,28

sahad-00 avatar May 28 '25 23:05 sahad-00

What are the make of these devices?

MichaelVerdon avatar Jun 16 '25 11:06 MichaelVerdon

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 attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar Jul 14 '25 11:07 github-actions[bot]

Same issue.

Devices (info from Sentry):

  • 23108RN04Y (Android 15)
  • M2101K6G (Android 13)
  • TECNO LG6n (Android 12)
  • SM-M317F (Android 12)
  • RMX2155 (Android 12)
  • ONEPLUS A5010 (Android 10)

astrahov avatar Nov 01 '25 10:11 astrahov