我一直试图使一个FCM项目与Flutter2-3天。我想,反过来讲我经历的困难会更准确。
首先,我正常地创建了我的项目。然后我用flutterfire cli将Firebase集成到我的项目中。第一个错误是Execution failed for task ':app:mapDebugSourceSetPaths'
。出错了。我通过更改GMS版本从x.x.x.10 to x.x.x.15.
解决了这个问题
然后我将firebase消息添加到我的项目中,将minSdk错误设置为19并通过。然后,我更新了我的应用程序,以便按照文档中的代码接收后台通知。正确接收第一个通知后,在第二个通知时,应用程序崩溃,FATAL
。我再次尝试说,也许这是因为调试模式,但我得到了同样的错误再次,广播接收的消息为第二次。日志一到应用程序就会崩溃。
我的代码和Flutter输出
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()
),
);
}
}
::输出::
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.
让我的应用程序正常工作。
3条答案
按热度按时间kcugc4gi1#
我在Android 33上也遇到了同样的问题。他们似乎在这里解决了这个问题:https://github.com/firebase/flutterfire/issues/11142
等待修复,因为这是一个关键问题。
vs3odd8k2#
这个问题似乎只在Android版本33中存在。旧的还可以
ttcibm8c3#
我也收到了第一次通知在后台和第二次应用程序崩溃