I am making a flutter app with messaging feature, so I am trying to add notifications for my app, App is working fine, but when I send a test message from Firebase console, the app is receiving the broadcast, but instead of displaying the message in the CLI the app is getting closed.
I tried using try-catch in my main function but it doesn’t seem to work.
this is my main function, all code related to cloud messaging is here.
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
try {
var fcm = FirebaseMessaging.instance;
await fcm.requestPermission();
await fcm.setAutoInitEnabled(true);
await fcm.getToken().then((token) {
if (token != null) {
if (kDebugMode) {
print('this is the token $token');
}
saveToken(token);
}
});
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
} catch (e) {
print('The error that is occurred is $e');
}
runApp(MyApp());
}
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
if (kDebugMode) {
if (message.data.isNotEmpty) {
print('${message.notification?.title}/${message.notification?.body}');
}
}
}
this is the stack trace from the moment the firebase background service is started
I/FLTFireMsgService( 6234): FlutterFirebaseMessagingBackgroundService started!
D/EGL_emulation( 6234): eglMakeCurrent: 0xabb0dce0: ver 2 0 (tinfo 0x8ea97e50)
D/FLTFireMsgReceiver( 6234): broadcast received for message
D/AndroidRuntime( 6234): Shutting down VM
E/AndroidRuntime( 6234): FATAL EXCEPTION: main
E/AndroidRuntime( 6234): Process: co.kushalreddy.flash_chat, PID: 6234
E/AndroidRuntime( 6234): java.lang.RuntimeException: Unable to instantiate service co.kushalreddy.flash_chat.java.MyFirebaseMessagingService: java.lang.ClassNotFoundException: Didn't find class "co.kushalreddy.flash_chat.java.MyFirebaseMessagingService" on path: DexPathList[[zip file "/data/app/co.kushalreddy.flash_chat-R7UFRZNLFOzZC3mzUCJIYw==/base.apk"],nativeLibraryDirectories=[/data/app/co.kushalreddy.flash_chat-R7UFRZNLFOzZC3mzUCJIYw==/lib/x86, /data/app/co.kushalreddy.flash_chat-R7UFRZNLFOzZC3mzUCJIYw==/base.apk!/lib/x86, /system/lib, /vendor/lib]]
E/AndroidRuntime( 6234): at android.app.ActivityThread.handleCreateService(ActivityThread.java:3324)
E/AndroidRuntime( 6234): at android.app.ActivityThread.-wrap4(Unknown Source:0)
E/AndroidRuntime( 6234): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1677)
E/AndroidRuntime( 6234): at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime( 6234): at android.os.Looper.loop(Looper.java:164)
E/AndroidRuntime( 6234): at android.app.ActivityThread.main(ActivityThread.java:6494)
E/AndroidRuntime( 6234): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 6234): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
E/AndroidRuntime( 6234): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
E/AndroidRuntime( 6234): Caused by: java.lang.ClassNotFoundException: Didn't find class "co.kushalreddy.flash_chat.java.MyFirebaseMessagingService" on path: DexPathList[[zip file "/data/app/co.kushalreddy.flash_chat-R7UFRZNLFOzZC3mzUCJIYw==/base.apk"],nativeLibraryDirectories=[/data/app/co.kushalreddy.flash_chat-R7UFRZNLFOzZC3mzUCJIYw==/lib/x86, /data/app/co.kushalreddy.flash_chat-R7UFRZNLFOzZC3mzUCJIYw==/base.apk!/lib/x86, /system/lib, /vendor/lib]]
E/AndroidRuntime( 6234): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
E/AndroidRuntime( 6234): at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
E/AndroidRuntime( 6234): at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E/AndroidRuntime( 6234): at android.app.ActivityThread.handleCreateService(ActivityThread.java:3321)
E/AndroidRuntime( 6234): ... 8 more
I/zygote ( 6234): Do partial code cache collection, code=119KB,
data=79KB
I/zygote ( 6234): After code cache collection, code=119KB, data=79KB
I/zygote ( 6234): Increasing code cache capacity to 512KB
W/CloudMessagingReceiver( 6234): Message ack failed:
java.util.concurrent.TimeoutException: Timed out waiting for Task
E/WakeLock( 6234):
*gcore*:wake:com.google.firebase.iid.WakeLockHolder ** IS FORCE-
RELEASED ON TIMEOUT **
Lost connection to device.
2
Answers
do you have
FirebaseMessagingService
in theco.kushalreddy.flash_chat.java
if you believe that you have implemented the class properly then try by rebuild the project to ensure that the class is included in the application’s classpath
I am having same problem except I am not using firebase or any other package/plugin