I’ve been trying to make an fcm project with flutter for 2-3 days. I think it would be more accurate to tell about the difficulties I experienced in turn.
First, I created my project normally. Then I integrated Firebase into my project with flutterfire cli. My first error is Execution failed for task ':app:mapDebugSourceSetPaths'
. i got the error. I solved the problem by changing the GMS version from x.x.x.10 to x.x.x.15.
Then I added firebase messaging to my project, set the minSdk error to 19 and passed. Then I updated my application to receive backgroud notifications in accordance with the code in the documentation. After receiving the 1st notification properly, on the 2nd notification the app crashes with FATAL
. I tried again saying maybe it’s because of the debug mode, but I got the same error again, broadcast received for message for the 2nd time.
The application crashes as soon as the log arrives.
My code and flutter output;
import 'package:firebase_core/firebase_core.dart';
import 'dart:developer';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'firebase_options.dart';
import 'package:flutter/material.dart';
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp();
print("Handling a background message: ${message.messageId}");
}
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: "Simple App",
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
useMaterial3: true,
brightness: Brightness.light,
),
home: const MyHomePage(title: 'Simple App'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void showNotification() {
setState(() {
_counter++;
});
}
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(
"Kimlik Doğrulama Servisi",
style: TextStyle(fontWeight: FontWeight.bold),
),
),
body: Center(
child: Container()
),
);
}
}
:: OUTPUT ::
D/FLTFireMsgReceiver(19336): broadcast received for message
W/FirebaseMessaging(19336): Unable to log event: analytics library is missing
W/FirebaseMessaging(19336): Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.
D/CompatibilityChangeReporter(19336): Compat change id reported: 160794467; UID 10868; state: ENABLED
I/flutter (19336): Handling a background message: 0:1687133276773552%48e9d64e48e9d64e
W/FirebaseMessaging(19336): Unable to log event: analytics library is missing
D/FLTFireMsgReceiver(19336): broadcast received for message
D/AndroidRuntime(19336): Shutting down VM
E/AndroidRuntime(19336): FATAL EXCEPTION: main
E/AndroidRuntime(19336): Process: com.example.madmin_mobile, PID: 19336
E/AndroidRuntime(19336): java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Class.isInterface()' on a null object reference
E/AndroidRuntime(19336): at java.lang.Class.isAssignableFrom(Class.java:589)
E/AndroidRuntime(19336): at android.os.Parcel.readParcelableCreatorInternal(Parcel.java:4865)
E/AndroidRuntime(19336): at android.os.Parcel.readParcelableInternal(Parcel.java:4778)
E/AndroidRuntime(19336): at android.os.Parcel.readValue(Parcel.java:4544)
E/AndroidRuntime(19336): at android.os.Parcel.readValue(Parcel.java:4324)
E/AndroidRuntime(19336): at android.os.Parcel.-$$Nest$mreadValue(Unknown Source:0)
E/AndroidRuntime(19336): at android.os.Parcel$LazyValue.apply(Parcel.java:4422)
E/AndroidRuntime(19336): at android.os.Parcel$LazyValue.apply(Parcel.java:4381)
E/AndroidRuntime(19336): at android.os.BaseBundle.getValueAt(BaseBundle.java:394)
E/AndroidRuntime(19336): at android.os.BaseBundle.getValue(BaseBundle.java:374)
E/AndroidRuntime(19336): at android.os.BaseBundle.getValue(BaseBundle.java:357)
E/AndroidRuntime(19336): at android.os.BaseBundle.get(BaseBundle.java:696)
E/AndroidRuntime(19336): at android.os.Bundle.getParcelable(Bundle.java:947)
E/AndroidRuntime(19336): at android.content.Intent.getParcelableExtra(Intent.java:9558)
E/AndroidRuntime(19336): at io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingBackgroundExecutor.executeDartCallbackInBackgroundIsolate(FlutterFirebaseMessagingBackgroundExecutor.java:235)
E/AndroidRuntime(19336): at io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingBackgroundService.lambda$onHandleWork$0(FlutterFirebaseMessagingBackgroundService.java:146)
E/AndroidRuntime(19336): at io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingBackgroundService$$ExternalSyntheticLambda0.run(Unknown Source:4)
E/AndroidRuntime(19336): at android.os.Handler.handleCallback(Handler.java:942)
E/AndroidRuntime(19336): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(19336): at android.os.Looper.loopOnce(Looper.java:226)
E/AndroidRuntime(19336): at android.os.Looper.loop(Looper.java:313)
E/AndroidRuntime(19336): at android.app.ActivityThread.main(ActivityThread.java:8757)
E/AndroidRuntime(19336): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(19336): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
E/AndroidRuntime(19336): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
I/Process (19336): Sending signal. PID: 19336 SIG: 9
Lost connection to device.
make my app work properly.
2
Answers
I am experiencing the same with Android 33.
They seem to be addressing it here:
https://github.com/firebase/flutterfire/issues/11142
Waiting for a fix as this is a critical issue.
Seems like this issue is only there in Android Version 33. Older ones work fine