X-SLAYER / flutter_overlay_window

Flutter plugin for displaying flutter app over other apps on the screen
https://pub.dev/packages/flutter_overlay_window
MIT License
103 stars 108 forks source link

Attempt to invoke virtual method 'wd.a io.flutter.embedding.engine.a.j()' on a null object reference #129

Open OsamaQureshi796 opened 3 weeks ago

OsamaQureshi796 commented 3 weeks ago

Dear @X-SLAYER

I'm using flutter_overlay_window latest version.

Unfortunately i'm getting lots of fatal exceptions in firebase crashlytics regarding flutter_overlay_window.

Bellow is the crash report from firebase crashlytics.

Fatal Exception: java.lang.RuntimeException: Unable to create service flutter.overlay.window.flutter_overlay_window.OverlayService: java.lang.NullPointerException: Attempt to invoke virtual method 'wd.a io.flutter.embedding.engine.a.j()' on a null object reference
       at android.app.ActivityThread.handleCreateService(ActivityThread.java:4627)
       at android.app.ActivityThread.access$1600(ActivityThread.java:301)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2175)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:246)
       at android.app.ActivityThread.main(ActivityThread.java:8550)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'wd.a io.flutter.embedding.engine.a.j()' on a null object reference
       at flutter.overlay.window.flutter_overlay_window.OverlayService.<init>(:35)
       at java.lang.Class.newInstance(Class.java)
       at android.app.AppComponentFactory.instantiateService(AppComponentFactory.java:129)
       at androidx.core.app.CoreComponentFactory.instantiateService()
       at android.app.ActivityThread.handleCreateService(ActivityThread.java:4606)
       at android.app.ActivityThread.access$1600(ActivityThread.java:301)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2175)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:246)
       at android.app.ActivityThread.main(ActivityThread.java:8550)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

Could you please take some of your time look into this issue.

Thanks

PedroAlvim commented 3 weeks ago

I'm having the same problem as you, for me the flow that happens is that when the application dies in a few moments the overlay disappears, but the overlay service still exists for a short period of time. If the user opens the application in this period, the application crashes

OsamaQureshi796 commented 3 weeks ago

Hi @PedroAlvim ,

Yes it happens with me as well, if i remove app from the recent apps and bubble is active so after some time it'll shows that app is keeps stopping.

WhatsApp Image 2024-08-22 at 5 37 15 PM

PedroAlvim commented 3 weeks ago

Hi @OsamaQureshi796,

In my case, finding the cause in OverlayService, and fixed it there, what changed was that the flutterChannel and overlayMessageChannel variables no longer have initiators, and just before using them in onStartCommand, I check if it is null and fill it in if necessary.

I'll try to make a pull request later with this fix, I don't know if it's the best way, but it definitely solved my problem.