Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PlatformException/ClassCastException: java.lang.Integer cannot be cast to java.lang.Long #1796

Closed
timobaehr opened this issue Nov 20, 2022 · 9 comments · Fixed by #1798
Closed

Comments

@timobaehr
Copy link

timobaehr commented Nov 20, 2022

Describe the bug
If I run the app on Android 6 devices, the app crashes. On Android 13 everything works fine. Maybe same bug like #1794?

Affected versions
Looks like this error came up in v10.0.0 and later. 9.x version works.
I tested:

  • 10.0.0 - Crash
  • 12.0.3+1 - Crash

Stacktrace from debug version

Launching lib/main.dart on SGP621 in debug mode...
...
E/MethodChannel#dexterous.com/flutter/local_notifications(22616): Failed to handle method call
E/MethodChannel#dexterous.com/flutter/local_notifications(22616): java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
E/MethodChannel#dexterous.com/flutter/local_notifications(22616): 	at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.initialize(FlutterLocalNotificationsPlugin.java:1499)
E/MethodChannel#dexterous.com/flutter/local_notifications(22616): 	at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:1293)
E/MethodChannel#dexterous.com/flutter/local_notifications(22616): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/MethodChannel#dexterous.com/flutter/local_notifications(22616): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#dexterous.com/flutter/local_notifications(22616): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/MethodChannel#dexterous.com/flutter/local_notifications(22616): 	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(D8$$SyntheticClass)
E/MethodChannel#dexterous.com/flutter/local_notifications(22616): 	at android.os.Handler.handleCallback(Handler.java:739)
E/MethodChannel#dexterous.com/flutter/local_notifications(22616): 	at android.os.Handler.dispatchMessage(Handler.java:95)
E/MethodChannel#dexterous.com/flutter/local_notifications(22616): 	at android.os.Looper.loop(Looper.java:234)
E/MethodChannel#dexterous.com/flutter/local_notifications(22616): 	at android.app.ActivityThread.main(ActivityThread.java:5526)
E/MethodChannel#dexterous.com/flutter/local_notifications(22616): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#dexterous.com/flutter/local_notifications(22616): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
E/MethodChannel#dexterous.com/flutter/local_notifications(22616): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
E/flutter (22616): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, java.lang.Integer cannot be cast to java.lang.Long, null, java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
E/flutter (22616): 	at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.initialize(FlutterLocalNotificationsPlugin.java:1499)
E/flutter (22616): 	at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:1293)
E/flutter (22616): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/flutter (22616): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/flutter (22616): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/flutter (22616): 	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(D8$$SyntheticClass)
E/flutter (22616): 	at android.os.Handler.handleCallback(Handler.java:739)
E/flutter (22616): 	at android.os.Handler.dispatchMessage(Handler.java:95)
E/flutter (22616): 	at android.os.Looper.loop(Looper.java:234)
E/flutter (22616): 	at android.app.ActivityThread.main(ActivityThread.java:5526)
E/flutter (22616): 	at java.lang.reflect.Method.invoke(Native Method)
E/flutter (22616): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
E/flutter (22616): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
E/flutter (22616): )
E/flutter (22616): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:653:7)
E/flutter (22616): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:296:18)
E/flutter (22616): <asynchronous suspension>
E/flutter (22616): #2      AndroidFlutterLocalNotificationsPlugin.initialize (package:flutter_local_notifications/src/platform_flutter_local_notifications.dart:151:12)
E/flutter (22616): <asynchronous suspension>
E/flutter (22616): #3      initLocalNotifications (package:energy_tracker/main_local_notification.dart:44:3)
E/flutter (22616): <asynchronous suspension>
E/flutter (22616): #4      main (package:energy_tracker/main.dart:126:5)
E/flutter (22616): <asynchronous suspension>

To Reproduce

  1. Try to run the app
  2. See crash, freezes on splashscreen
@timobaehr timobaehr reopened this Nov 21, 2022
@timobaehr
Copy link
Author

I folowed the latest README for Android 6 and 7, but app still crashes at app start.

@MaikuB
Copy link
Owner

MaikuB commented Nov 21, 2022

Haven't seen this before, which version of the plugin is this stack trace from? Do you register a function against the onDidReceiveBackgroundNotificationResponse callback?

@timobaehr
Copy link
Author

On emulator with Android 7 I cannot reproduce the issue. Is happening on real device with Android 6 (Sony Xperia Compact Tablet, Sony Xperia Compact). I own these devices and can retest.

  flutter_local_notifications:
    dependency: "direct main"
    description:
      name: flutter_local_notifications
      url: "https://pub.dartlang.org"
    source: hosted
    version: "12.0.3+1"

  flutter_local_notifications_platform_interface:
    dependency: transitive
    description:
      name: flutter_local_notifications_platform_interface
      url: "https://pub.dartlang.org"
    source: hosted
    version: "6.0.0"
[✓] Flutter (Channel stable, 3.3.8, on macOS 12.6.1 21G217 darwin-arm, locale de-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)

@timobaehr
Copy link
Author

onDidReceiveBackgroundNotificationResponse

Yes, is defined. This is the implemenation of the funktion:

Future<void> onReceivedNotification(NotificationResponse response) async {
  selectedNotificationPayload = response.payload;
  selectNotificationSubject.add(response.payload);
}

@MaikuB
Copy link
Owner

MaikuB commented Nov 21, 2022

What does your initialize call look like?

@MaikuB
Copy link
Owner

MaikuB commented Nov 21, 2022

I've opened a PR that I believe would fix the issue. Are you able to help test to confirm if this fixes on the device but having your app point to that branch on the repository? This page provides some examples on how to do this https://dart.dev/tools/pub/dependencies#git-packages

@timobaehr
Copy link
Author

Retested on Sony Xperia Z3 Compact (D5803). The issue is solved by this pull request. I move the new libraries on beta test now for real users.

I want to thank you so much. Your response time and the fix was immediately fast! I find that absolutely not self-evident. Thank you for your great work.

For others that are affected:

  flutter_local_notifications:
    git:
      url: https://github.com/MaikuB/flutter_local_notifications.git
      path: flutter_local_notifications
      ref: fix-callback-handle-parsing

@MaikuB
Copy link
Owner

MaikuB commented Nov 21, 2022

FYI I'm merging the PR in to release the fix and will delete the branch so I suggest you don't point to that branch for your release as otherwise the build will fail. If you're going to use a Git dependency then fork and maintain your own branch. New release will be published in the next few minutes

@MaikuB
Copy link
Owner

MaikuB commented Nov 21, 2022

FYI 12.0.4 has now been published

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants