[Messaging] getToken() hangs infinitely and onNewToken() is never called when using Firebase BOM 34.12.0 with androidx.datastore 1.3.0-alpha07

Aperta
#8,040 2 commenti 2 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
38/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
android, firebase, kotlin
Ambito
mobile-dev

Direzione di ricerca

Riproduci il problema con le versioni e le dipendenze di build.gradle.kts, quindi traccia il comportamento di FirebaseMessaging.getInstance().token e di onNewToken() di MyFirebaseMessagingService.kt con Firebase BOM 34.12.0 e androidx.datastore 1.3.0-alpha07. Confronta con Datastore 1.3.0-alpha06 o Firebase BOM 33.16.0; il lavoro è completato quando il recupero del token termina e onNewToken() viene chiamato con la combinazione interessata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

api: messaging
[READ] Step 1: Are you in the right place?

Yes.

[REQUIRED] Step 2: Describe your environment
  • Android Studio version: Android Studio Panda 4 | 2025.3.4 RC 1
  • Firebase Component: firebase-messaging
  • Component version: Firebase BOM 34.12.0 (Bug also depends on androidx.datastore:1.3.0-alpha07)
[REQUIRED] Step 3: Describe the problem

I am using Firebase Cloud Messaging in my project, managed via the Firebase BOM. I also use androidx.datastore to store user preferences.

There seems to be a severe conflict or bug when combining recent versions of the Firebase BOM with the latest alpha version of Jetpack Datastore.

The Issue:

  1. FirebaseMessagingService().onNewToken() is never called, not even on a fresh installation of the app.
  2. When calling FirebaseMessaging.getInstance().getToken(), the task runs infinitely and never completes (neither succeeds nor fails).

Version specific behavior:

  • The bug occurs when using Firebase BOM 34.12.0 in combination with androidx.datastore 1.3.0-alpha07.
  • If I downgrade androidx.datastore to 1.3.0-alpha06, the issue disappears and FCM works correctly.
  • Alternatively, if I keep Datastore at 1.3.0-alpha07 but downgrade the Firebase BOM to 33.16.0, the issue also disappears.

This indicates a dependency clash between the newest Datastore alpha and the newest Firebase BOM, causing the FCM token generation/retrieval task to deadlock or silently fail.

The behavior can be reproduced in a fresh project.

Steps to reproduce:
  1. Create a project using Firebase BOM 34.12.0 and firebase-messaging.
  2. Add androidx.datastore:datastore-preferences:1.3.0-alpha07.
  3. Set up a basic FirebaseMessagingService.
  4. Install the app fresh. Notice that onNewToken() is missing.
  5. Attempt to fetch the token manually via FirebaseMessaging.getInstance().token. Notice that the listener is never triggered.
Relevant Code:

build.gradle.kts (Dependencies):

dependencies {
    // Firebase
    implementation(platform("com.google.firebase:firebase-bom:34.12.0"))
    implementation("com.google.firebase:firebase-messaging")

    // Datastore (Causes the FCM infinite hang with the BOM above)
    implementation("androidx.datastore:datastore-preferences:1.3.0-alpha07")
    // Note: Reverting to 1.3.0-alpha06 fixes the Firebase issue.
}

MyFirebaseMessagingService.kt:

import android.util.Log
import com.google.firebase.messaging.FirebaseMessagingService

class MyFirebaseMessagingService : FirebaseMessagingService() {

    override fun onNewToken(token: String) {
        super.onNewToken(token)
        // BUG: This is NEVER called on fresh install when using the dependency combination above.
        Log.d("FCM_TEST", "Refreshed token: $token")
    }
}

MainActivity.kt (Manual Token Fetching):

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.google.firebase.messaging.FirebaseMessaging

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        
        Log.d("FCM_TEST", "Fetching FCM token...")
        
        FirebaseMessaging.getInstance().token.addOnCompleteListener { task ->
            // BUG: This callback is NEVER reached. It hangs infinitely.
            if (!task.isSuccessful) {
                Log.w("FCM_TEST", "Fetching FCM registration token failed", task.exception)
                return@addOnCompleteListener
            }

            val token = task.result
            Log.d("FCM_TEST", "FCM Token: $token")
        }
    }
}
Lingua principale
Java
Stelle
2.6k
Fork
733
Merge medio
2g 15h
PR unite (30g)
72

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di firebase/firebase-android-sdk

Tutte le issue di firebase/firebase-android-sdk

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.