appsflyer-flutter-plugin icon indicating copy to clipboard operation
appsflyer-flutter-plugin copied to clipboard

Init AppsFlyer SDK after coming from a background push notification on Android device causes a NullPointerException

Open amitrotner opened this issue 4 years ago • 1 comments

Describe the bug Init causes NullPointerException after entering the app from a push notification.

To Reproduce Steps to reproduce the behavior:

  1. Use Firebase messaging for sending a push notification in the background process when the app is terminated
  2. Click on notification to enter the app
  3. Init AppsFlyer SDK
  4. See error:
E/MethodChannel#af-api: Failed to handle method call
    java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference
        at com.appsflyer.AppsFlyerLibCore.start(:921)
        at com.appsflyer.AppsFlyerLibCore.start(:902)
        at com.appsflyer.AppsFlyerLibCore.start(:897)
        at com.appsflyer.appsflyersdk.AppsflyerSdkPlugin.initSdk(AppsflyerSdkPlugin.java:586)
        at com.appsflyer.appsflyersdk.AppsflyerSdkPlugin.onMethodCall(AppsflyerSdkPlugin.java:128)
        at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
        at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
        at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:818)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:336)
        at android.os.Looper.loop(Looper.java:197)
        at android.app.ActivityThread.main(ActivityThread.java:8016)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)

Expected behavior No error.

Smartphone (please complete the following information):

  • Device: Xiaomi Mi 10T Pro 5G
  • OS: Android 11 (API 30)

Additional context: Same problem as this closed issue: https://github.com/AppsFlyerSDK/appsflyer-flutter-plugin/issues/109 If the app is in the background, but not terminated, there is no error as the SDK has already been initialized.

amitrotner avatar Nov 11 '21 13:11 amitrotner

I'm also receiving a lot of error reports regarding this bug. Looking forward to a fix.

pierrea avatar Nov 17 '21 13:11 pierrea

Same issue

minoesteban avatar May 22 '23 12:05 minoesteban

plugin fix for this issue was released on v6.11.3

GM-appsflyer avatar Jul 12 '23 09:07 GM-appsflyer