flutter_local_notifications icon indicating copy to clipboard operation
flutter_local_notifications copied to clipboard

PlatformException checkPermission on a null object reference Unknown Source

Open EArminjon opened this issue 1 year ago • 6 comments

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
package entreprise.flutter.radio_app

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
}

AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          package="entreprise.flutter.radio_app">

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"/>
    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

    <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
    <uses-permission android:name="android.permission.USE_EXACT_ALARM"/>
    <queries>
        <!-- If your app opens https URLs -->
        <intent>
            <action android:name="android.intent.action.VIEW"/>
            <data android:scheme="https"/>
        </intent>
        <!-- If your app makes calls -->
        <intent>
            <action android:name="android.intent.action.DIAL"/>
            <data android:scheme="tel"/>
        </intent>
        <!-- If your app emails -->
        <intent>
            <action android:name="android.intent.action.SEND"/>
            <data android:mimeType="*/*"/>
        </intent>
    </queries>
    <application
            android:name="${applicationName}"
            android:label="@string/app_name"
            android:icon="@mipmap/ic_launcher"
            android:usesCleartextTraffic="true">
        <meta-data
                android:name="com.google.android.gms.ads.APPLICATION_ID"
                android:value="${admobAppId}"/>
        <meta-data android:name="com.wonderpush.sdk.buildConfigPackage"
                   android:value="entreprise.flutter.radio_app"/>
        <activity
                android:exported="true"
                android:name="com.ryanheise.audioservice.AudioServiceActivity"
                android:launchMode="singleTop"
                android:theme="@style/LaunchTheme"
                android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
                android:hardwareAccelerated="true"
                android:windowSoftInputMode="adjustResize"
                tools:ignore="Instantiatable">
            <meta-data
                    android:name="io.flutter.embedding.android.NormalTheme"
                    android:resource="@style/NormalTheme"
            />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
                android:name="flutterEmbedding"
                android:value="2"/>

        <service android:name="com.ryanheise.audioservice.AudioService"
                 android:foregroundServiceType="mediaPlayback"
                 android:exported="false" tools:ignore="Instantiatable">
            <intent-filter>
                <action android:name="android.media.browse.MediaBrowserService"/>
            </intent-filter>
        </service>
        >

        <receiver android:name="com.ryanheise.audioservice.MediaButtonReceiver"
                  android:exported="false" tools:ignore="Instantiatable">
            <intent-filter>
                <action android:name="android.intent.action.MEDIA_BUTTON"/>
            </intent-filter>
        </receiver>

        <receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
        <receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
                <action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
                <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
            </intent-filter>
        </receiver>
    </application>
</manifest>
Complete dependencies list

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
[!] 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.

EArminjon avatar Dec 17 '23 16:12 EArminjon

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

jaskiratAtNexG avatar Dec 21 '23 09:12 jaskiratAtNexG

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

No, that's why I created this issue.

EArminjon avatar Dec 21 '23 12:12 EArminjon

@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

MaikuB avatar Dec 26 '23 21:12 MaikuB

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

EArminjon avatar Dec 26 '23 21:12 EArminjon

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)

MaikuB avatar Dec 26 '23 21:12 MaikuB

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??

jaskiratAtNexG avatar Jan 09 '24 11:01 jaskiratAtNexG