FirebaseInstanceIdService and FirebaseInstanceId.getToken() no longer work
Deprecation warning or build error on FirebaseInstanceIdServiceShort answer
Move token handling into a class that extends FirebaseMessagingService and override onNewToken, which runs when a token is first created and whenever it changes. To read the current token at any time, call FirebaseMessaging.getInstance().getToken() and listen for the result.
Fix it fast
1Find out which cause you have
Find every place the old classes are used.
grep -rn -E "FirebaseInstanceId(Service)?|onTokenRefresh" app/src2Match what you see, then jump to its fix
What does the error look like?
Deprecation warning or build error on FirebaseInstanceIdServiceDeprecation warning on FirebaseInstanceId.getInstance().getToken()
Cause 1 of 2
A service still extends FirebaseInstanceIdService
1Check
Find the class that extends FirebaseInstanceIdService and the service entry that registers it in AndroidManifest.xml.
grep -rn "FirebaseInstanceIdService" app/src2Fix
Delete that service and its manifest entry. In your FirebaseMessagingService subclass, override onNewToken and send the token to your server. Register that service with the MESSAGING_EVENT action.
class MyMessagingService : FirebaseMessagingService() {
override fun onNewToken(token: String) {
sendRegistrationToServer(token)
}
}
// AndroidManifest.xml
// <service android:name=".MyMessagingService" android:exported="false">
// <intent-filter><action android:name="com.google.firebase.MESSAGING_EVENT" /></intent-filter>
// </service>3Verify
Clear the app data and start the app. onNewToken should log a token.
adb logcat | grep -i tokenConfirmed by firebase.google.com
Cause 2 of 2
Code calls FirebaseInstanceId.getInstance().getToken()
1Check
That call is the old way to read the token on demand.
grep -rn "FirebaseInstanceId.getInstance" app/src2Fix
Use FirebaseMessaging and handle the task result; the token can fail to arrive, so check isSuccessful.
FirebaseMessaging.getInstance().token.addOnCompleteListener { task ->
if (!task.isSuccessful) {
Log.w("FCM", "Fetching FCM registration token failed", task.exception)
return@addOnCompleteListener
}
val token = task.result
// send token to your server
}3Verify
Run the app and look for the logged token in Logcat.
adb logcat | grep FCMConfirmed by firebase.google.com
How do I stop it coming back?
- Send the token to your server from onNewToken, and fetch it again on app start.
- Read the current Firebase Cloud Messaging Android guide when you upgrade the BoM, since token APIs are being phased toward Firebase Installation IDs.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- Nuclear Home VideoA video-streaming Android app built from scratch, engineered for smooth playback.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
Related fixes
Mobile apps
Logcat warns that FCM has no default notification channel in AndroidManifest
Notification does not appear on Android 8 and later
This is a warning, not a crash.
3 causes, each with a fixMobile apps
AGP 9 marks the android block as deprecated or fails on BaseExtension
java.lang.ClassCastException: class com.android.build.gradle.internal.dsl.ApplicationExtensionImpl$AgpDecorated_Decorated cannot be cast to class com.android.build.gradle.BaseExtension
AGP 9.0 uses only the new public DSL interfaces.
3 causes, each with a fixMobile apps
The editor cannot find R, so every R.string and R.id turns red
Unresolved reference: R
R is a class that the build generates from your res folder, in the package named by the module's namespace.
4 causes, each with a fixMobile apps
Android Studio says it could not identify the launch activity when you press Run
Run > Edit Configurations > Launch Options is set to Nothing or to a class that no longer exists
Android Studio launches the activity marked with a MAIN action and a LAUNCHER category in the merged manifest.
3 causes, each with a fixMobile apps
Java and Kotlin compile to different JVM targets in an Android module
Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (1.8) and 'kaptGenerateStubsDebugKotlin' (17)
Java and Kotlin tasks in the same module are compiling for different JVM targets, for example 1.8 and 17.
2 causes, each with a fixMobile apps
Manifest.permission.POST_NOTIFICATIONS shows red or does not resolve
Cannot resolve symbol 'POST_NOTIFICATIONS'
POST_NOTIFICATIONS exists only from API level 33.
4 causes, each with a fix