MaikuB / flutter_local_notifications

A Flutter plugin for displaying local notifications on Android, iOS, macOS and Linux
2.44k stars 1.39k forks source link

PlatformException checkPermission on a null object reference Unknown Source #2184

Closed EArminjon closed 5 days ago

EArminjon commented 9 months ago

Describe the bug

I've upgradedmy flutter_local_notification package and got a huge number of reports of the following issue on my Firebase Crashlytics. It happen at launch on Android 13+ devices. I didn't have a precision vision of what is happening but I will update this issue while i will got more hint. Please help.

Crashlytics report :

Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: PlatformException(error, Attempt to invoke virtual method 'int android.content.Context.checkPermission(java.lang.String, int, int)' on a null object reference, null, java.lang.NullPointerException: Attempt to invoke virtual method 'int android.content.Context.checkPermission(java.lang.String, int, int)' on a null object reference
    at androidx.core.content.a.a(Unknown Source:41)
    at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.requestNotificationsPermission(Unknown Source:24)
    at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(Unknown Source:390)
    at ma.k$a.a(Unknown Source:17)
    at ba.c.l(Unknown Source:18)
    at ba.c.m(Unknown Source:40)
    at ba.c.i(Unknown Source:0)
    at ba.b.run(Unknown Source:12)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:346)
    at android.os.Looper.loop(Looper.java:475)
    at android.app.ActivityThread.main(ActivityThread.java:7950)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)

To Reproduce My home devices aren't able to reproduce the issue even Samsung Test Lab or Browserstack.

Expected behavior

Clean crashlytics board.

Sample code to reproduce the problem

Not yet available (once i will got more hint, i will try to provide one).

Versions used flutter_local_notifications: 16.2.0 flutter: 3.16.4

MainActivity.kt ```kotlin package entreprise.flutter.radio_app import io.flutter.embedding.android.FlutterActivity class MainActivity: FlutterActivity() { } ```
AndroidManifest.xml ```xml > ```
Complete dependencies list ```yaml environment: sdk: '3.2.3' flutter: '3.16.4' dependencies: flutter: sdk: flutter # Firebase firebase_core: 2.24.2 firebase_crashlytics: 3.4.8 firebase_analytics: 10.7.4 # Ads google_mobile_ads: 4.0.0 # Push notifications wonderpush_flutter: 2.3.7 wonderpush_fcm_flutter: 1.0.7 # Audio just_audio: 0.9.36 audio_session: 0.1.18 audio_service: 0.18.12 # Storage shared_preferences: 2.2.2 # Devices url_launcher: 6.2.2 volume_controller: 2.0.7 flutter_to_airplay: 2.0.4 device_info_plus: 9.1.1 package_info_plus: 5.0.1 share: 2.0.4 # State management provider: 6.1.1 flutter_bloc: 8.1.3 rxdart: 0.27.7 # Dart misc equatable: 2.0.5 collection: 1.18.0 dartz: 0.10.1 # Others http: 1.1.2 intl: 0.19.0 cupertino_icons: 1.0.6 html: 0.15.4 app_settings: 5.1.1 flutter_local_notifications: 16.2.0 webview_flutter: 4.4.2 webview_flutter_android: 3.13.0 webview_flutter_wkwebview: 3.9.4 timezone: 0.9.2 crypto: 3.0.3 in_app_review: 2.0.8 flutter_speed_dial: 7.0.0 flutter_native_splash: 2.3.8 dev_dependencies: flutter_test: sdk: flutter flutter_launcher_icons: 0.13.1 flutter_lints: 3.0.1 ```
Flutter doctor -v ```console [!] Flutter (Channel stable, 3.16.4, on Microsoft Windows [version 10.0.19045.3570], locale fr-FR) • Flutter version 3.16.4 on channel stable at C:\Users\engue\fvm\versions\3.16.4 ! The flutter binary is not on your path. Consider adding C:\Users\engue\fvm\versions\3.16.4\bin to your path. ! The dart binary is not on your path. Consider adding C:\Users\engue\fvm\versions\3.16.4\bin to your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision 2e9cb0aa71 (6 days ago), 2023-12-11 14:35:13 -0700 • Engine revision 54a7145303 • Dart version 3.2.3 • DevTools version 2.28.4 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upg rades. [√] Windows Version (Installed version of Windows is version 10 or higher) [√] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at D:\Android • Platform android-34, build-tools 34.0.0 • Java binary at: C:\Users\engue\AppData\Local\Programs\Android Studio\jbr\bin\java • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314) • All Android licenses accepted. [√] Chrome - develop for the web • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe [√] Visual Studio - develop Windows apps (Visual Studio Community 2019 16.11.18) • Visual Studio at D:\dev • Visual Studio Community 2019 version 16.11.32802.440 • Windows 10 SDK version 10.0.22621.0 [√] Android Studio (version 2023.1) • Android Studio at C:\Users\engue\AppData\Local\Programs\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314) [√] IntelliJ IDEA Ultimate Edition (version 2023.3) • IntelliJ at C:\Users\engue\AppData\Local\Programs\IntelliJ IDEA Ultimate • Flutter plugin version 77.0.1 • Dart plugin version 233.11799.172 [√] Connected device (3 available) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [version 10.0.19045.3570] • Chrome (web) • chrome • web-javascript • Google Chrome 120.0.6099.109 • Edge (web) • edge • web-javascript • Microsoft Edge 119.0.2151.72 [√] Network resources • All expected network resources are available. ! Doctor found issues in 1 category. ```
jaskiratAtNexG commented 9 months ago

getting same error in release mode, did you find any solution??

EArminjon commented 9 months ago

getting same error in release mode, did you find any solution??

No, that's why I created this issue.

MaikuB commented 9 months ago

@EArminjon as you've commented on https://github.com/MaikuB/flutter_local_notifications/issues/2067, hope you have seen the discussions there. This would be something you need to check in your call as it's a result of trying to request permissions when the app is in the background or isn't running

EArminjon commented 9 months ago

@MaikuB I'm still waiting for an answer from the linked post... I cannot go ahead. Cannot blind push that in production :/

MaikuB commented 9 months ago

Have you looked at your code on when you're trying to request permissions though? That is the main part I was trying to highlight as the maintainer of the audio service plugin themselves states that this is the reason. Note that either way it's not a bug with this plugin as you have check that you're calling this when the app is running as otherwise the native Android API itself throws an exception (hence why it's not a bug in the plugin)

jaskiratAtNexG commented 8 months ago

getting same error in release mode, did you find any solution??

No, that's why I created this issue.

Hi did you find any solution to this problem??

MaikuB commented 5 days ago

Closing due to lack of updates from OP particularly on checking the permission check is done. I saw the message on waiting a response in regards to this question and not blindly pushing to production. I'd suggest looking at beta versions. From the flutter_local_notifications plugin side, it is following the appropriate logic in calling the correct APIs so isn't a bug with the plugin. I can't help further on this as a result as is another reason why I'm closing this. I would suggest using other forums to see if there are others who have worked on apps similar to yours @EArminjon . This may require you to provide more details e.g. a link to a repo with a minimal app that mimics what you're doing in your real app