[firebase_messaging]: PHONE_REGISTRATION_ERROR during FCM token generation #16962
Description
Is there an existing issue for this?
- I have searched the existing issues.
Which plugins are affected?
Messaging, Core
Which platforms are affected?
Android
Description
When attempting to generate an FCM token using FirebaseMessaging.instance.getToken()
in a Flutter app, the following error occurs:
[firebase_messaging/unknown] java.io.IOException: java.util.concurrent.ExecutionException: java.io.IOException: PHONE_REGISTRATION_ERROR
Expected Behavior
- The FCM token should be generated successfully when Google Play Services is available and correctly configured.
Actual Behavior
- The app fails to generate the FCM token and throws a
PHONE_REGISTRATION_ERROR
.
Additional Notes
- Google Play Services is verified to be available (
GooglePlayServicesAvailability.success
). - Internet connectivity is stable.
- This issue occurs on Android. The app has the necessary permissions (
INTERNET
andPOST_NOTIFICATIONS
) configured.
Reproducing the issue
Steps to reproduce:
- Create a Flutter project and integrate Firebase using
firebase_core
andfirebase_messaging
. - Add the required
google-services.json
file to the project and set up Firebase as per the documentation. - Request an FCM token using `FirebaseMessaging.instance.getToken() in this device
Device Information
- Device Name: Realme 6
- Manufacturer: Realme
- Model Number: RMX2001
- Operating System Version: Android 11
- Processor: Octa-core
- RAM/Storage Configuration: 6GB RAM / 128GB Storage
- Custom UI/OS Details: Realme UI 2.0
- Observe the error in the logs.
Minimal reproducible example:
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text("FCM Token Generation")),
body: Center(
child: ElevatedButton(
onPressed: () async {
try {
String? token = await FirebaseMessaging.instance.getToken();
print('FCM Token: $token');
} catch (e) {
print('Error generating FCM token: $e');
}
},
child: Text("Generate Token"),
),
),
),
);
}
}
### Firebase Core version
3.8.0
### Flutter Version
3.27.0
### Relevant Log Output
```shell
---------- ERROR ----------
I/flutter (29394): [2025-01-11 21:14:03.999040 | Catcher 2 | INFO] [firebase_messaging/unknown] java.io.IOException: java.util.concurrent.ExecutionException: java.io.IOException: PHONE_REGISTRATION_ERROR
I/flutter (29394): [2025-01-11 21:14:03.999336 | Catcher 2 | INFO]
I/flutter (29394): [2025-01-11 21:14:04.000439 | Catcher 2 | INFO] ------- STACK TRACE -------
I/flutter (29394): [2025-01-11 21:14:04.001468 | Catcher 2 | INFO] #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:646:7)
I/flutter (29394): [2025-01-11 21:14:04.001839 | Catcher 2 | INFO] #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18)
I/flutter (29394): [2025-01-11 21:14:04.002125 | Catcher 2 | INFO] <asynchronous suspension>
I/flutter (29394): [2025-01-11 21:14:04.002437 | Catcher 2 | INFO] #2 MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:534:43)
I/flutter (29394): [2025-01-11 21:14:04.002688 | Catcher 2 | INFO] <asynchronous suspension>
I/flutter (29394): [2025-01-11 21:14:04.002927 | Catcher 2 | INFO] #3 MethodChannelFirebaseMessaging.getToken (package:firebase_messaging_platform_interface/src/method_channel/method_channel_messaging.dart:248:11)
I/flutter (29394): [2025-01-11 21:14:04.003186 | Catcher 2 | INFO] <asynchronous suspension>
Flutter dependencies
Dart SDK 3.6.0
Flutter SDK 3.27.0
mobile_app 2.0.1+25
dependencies:
android_id 0.3.6 [flutter]
android_play_install_referrer 0.4.0
firebase_analytics: ^11.3.6
firebase_core: ^3.9.0
firebase_dynamic_links: ^6.0.11
firebase_in_app_messaging: ^0.8.0+11
firebase_messaging: ^15.1.6
firebase_remote_config: ^5.2.0
flutter:
sdk: flutter
Additional context and comments
- SHA-1 and SHA-256 keys are correctly configured in the Firebase Console.
- Permissions (
INTERNET
,POST_NOTIFICATIONS
) are added toAndroidManifest.xml
.
** A screenshot of the Sentry log has been included to provide more details about the error.
Please provide guidance on resolving the PHONE_REGISTRATION_ERROR
during FCM token generation.