[Messaging] getToken() hangs infinitely and onNewToken() is never called when using Firebase BOM 34.12.0 with androidx.datastore 1.3.0-alpha07
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 38/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 领域
- mobile-dev
调研方向
使用 build.gradle.kts 中的版本和依赖项重现该问题,然后在 Firebase BOM 34.12.0 和 androidx.datastore 1.3.0-alpha07 下跟踪 FirebaseMessaging.getInstance().token 以及 MyFirebaseMessagingService.kt 的 onNewToken() 行为。与 Datastore 1.3.0-alpha06 或 Firebase BOM 33.16.0 进行比较;当 token 获取完成且在受影响的组合下调用 onNewToken() 时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
[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:
FirebaseMessagingService().onNewToken()is never called, not even on a fresh installation of the app.- 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.datastoreto 1.3.0-alpha06, the issue disappears and FCM works correctly. - Alternatively, if I keep Datastore at
1.3.0-alpha07but 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:
- Create a project using Firebase BOM
34.12.0andfirebase-messaging. - Add
androidx.datastore:datastore-preferences:1.3.0-alpha07. - Set up a basic
FirebaseMessagingService. - Install the app fresh. Notice that
onNewToken()is missing. - 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")
}
}
}
- 主要语言
- Java
- 星标
- 2.6k
- 派生
- 733
- 平均合并
- 2 天 15 小时
- 30 天内合并 PR
- 72
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
firebase/firebase-android-sdk 的其他 Issue
-
api: remoteconfig
难度 2/5 1-3 小时 新手友好度 78/100
firebase/firebase-android-sdk#8827 ·
维护者通常 1 天内回复
-
Crashlytics plugin writes build ID lists in directory listing order, so APKs can differ between machines可能已有人在做 @mrober 于 8 天前认领。 未关闭api: crashlytics
难度 2/5 1-3 小时 新手友好度 72/100
firebase/firebase-android-sdk#8789 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
api: auth
难度 2/5 1-3 小时 新手友好度 68/100
firebase/firebase-android-sdk#8505 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 15/100
firebase/firebase-android-sdk#8835 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 25/100
firebase/firebase-android-sdk#8832 ·
维护者通常 1 天内回复
查看 firebase/firebase-android-sdk 的全部 Issue
相似的 Issue
-
good first issue
难度 2/5 1-3 小时 新手友好度 65/100
commons-app/apps-android-commons#7341 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
NationalSecurityAgency/ghidra#10220 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 80/100
维护者通常 1 天内回复