ryanheise / just_audio

Audio Player
1.06k stars 681 forks source link

RuntimeException on closing app with Ads SDK #781

Closed waplay closed 2 years ago

waplay commented 2 years ago

Which API doesn't behave as documented, and how does it misbehave? just_audio_background 0.0.1-beta.7

I have the problem that I get a native Android exception when I completely close the App. This problem only occurs if the app uses just_audio_background and ads SDK. In other applications without just_audio_background there is no error.

Minimal reproduction project Modified example

To Reproduce (i.e. user steps, not code) Steps to reproduce the behavior:

  1. Run app
  2. Wait for the banner to appear at the top
  3. Exit app
  4. See error

Error messages

E/ActivityThread( 6423): Activity com.ryanheise.audioservice.AudioServiceActivity has leaked IntentReceiver com.wortise.ads.h.c$a@fb7f311 that was originally registered here. Are you missing a call to unregisterReceiver()?
E/ActivityThread( 6423): android.app.IntentReceiverLeaked: Activity com.ryanheise.audioservice.AudioServiceActivity has leaked IntentReceiver com.wortise.ads.h.c$a@fb7f311 that was originally registered here. Are you missing a call to unregisterReceiver()?
E/ActivityThread( 6423):  at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:1736)
E/ActivityThread( 6423):  at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:1507)
E/ActivityThread( 6423):  at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1767)
E/ActivityThread( 6423):  at android.app.ContextImpl.registerReceiver(ContextImpl.java:1733)
E/ActivityThread( 6423):  at android.app.ContextImpl.registerReceiver(ContextImpl.java:1721)
E/ActivityThread( 6423):  at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:734)
E/ActivityThread( 6423):  at com.wortise.ads.banner.BannerAd.d(BannerAd.kt:6)
E/ActivityThread( 6423):  at com.wortise.ads.banner.BannerAd.a(BannerAd.kt:27)
E/ActivityThread( 6423):  at com.wortise.ads.banner.BannerAd.<init>(BannerAd.kt:300)
E/ActivityThread( 6423):  at com.wortise.ads.flutter.BannerAdView.<init>(BannerAdView.kt:40)
E/ActivityThread( 6423):  at com.wortise.ads.flutter.BannerAd.create(BannerAd.kt:12)
E/ActivityThread( 6423):  at io.flutter.plugin.platform.PlatformViewsController$1.createForTextureLayer(PlatformViewsController.java:197)
E/ActivityThread( 6423):  at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:122)
E/ActivityThread( 6423):  at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:60)
E/ActivityThread( 6423):  at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/ActivityThread( 6423):  at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/ActivityThread( 6423):  at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/ActivityThread( 6423):  at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/ActivityThread( 6423):  at android.os.Handler.handleCallback(Handler.java:938)
E/ActivityThread( 6423):  at android.os.Handler.dispatchMessage(Handler.java:99)
E/ActivityThread( 6423):  at android.os.Looper.loopOnce(Looper.java:210)
E/ActivityThread( 6423):  at android.os.Looper.loop(Looper.java:299)
E/ActivityThread( 6423):  at android.app.ActivityThread.main(ActivityThread.java:8302)
E/ActivityThread( 6423):  at java.lang.reflect.Method.invoke(Native Method)
E/ActivityThread( 6423):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
E/ActivityThread( 6423):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1037)
I/System.out( 6423): ### destroying audio handler interface
D/AndroidRuntime( 6423): Shutting down VM
E/AndroidRuntime( 6423): FATAL EXCEPTION: main
E/AndroidRuntime( 6423): Process: com.w.waplay, PID: 6423
E/AndroidRuntime( 6423): java.lang.RuntimeException: Unable to stop service com.ryanheise.audioservice.AudioService@bf464e2: java.lang.IllegalArgumentException: Receiver not registered: com.wortise.ads.h.c$a@fb7f311
E/AndroidRuntime( 6423):  at android.app.ActivityThread.handleStopService(ActivityThread.java:4839)
E/AndroidRuntime( 6423):  at android.app.ActivityThread.access$2200(ActivityThread.java:273)
E/AndroidRuntime( 6423):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2170)
E/AndroidRuntime( 6423):  at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime( 6423):  at android.os.Looper.loopOnce(Looper.java:210)
E/AndroidRuntime( 6423):  at android.os.Looper.loop(Looper.java:299)
E/AndroidRuntime( 6423):  at android.app.ActivityThread.main(ActivityThread.java:8302)
E/AndroidRuntime( 6423):  at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 6423):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
E/AndroidRuntime( 6423):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1037)
E/AndroidRuntime( 6423): Caused by: java.lang.IllegalArgumentException: Receiver not registered: com.wortise.ads.h.c$a@fb7f311
E/AndroidRuntime( 6423):  at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:1568)
E/AndroidRuntime( 6423):  at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:1799)
E/AndroidRuntime( 6423):  at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:779)
E/AndroidRuntime( 6423):  at com.wortise.ads.banner.BannerAd.g(BannerAd.kt:1)
E/AndroidRuntime( 6423):  at com.wortise.ads.banner.BannerAd.destroy(BannerAd.kt:1)
E/AndroidRuntime( 6423):  at com.wortise.ads.flutter.BannerAdView.dispose(BannerAdView.kt:51)
E/AndroidRuntime( 6423):  at io.flutter.plugin.platform.PlatformViewsController$1.dispose(PlatformViewsController.java:254)
E/AndroidRuntime( 6423):  at io.flutter.plugin.platform.PlatformViewsController.flushAllViews(PlatformViewsController.java:711)
E/AndroidRuntime( 6423):  at io.flutter.plugin.platform.PlatformViewsController.onDetachedFromJNI(PlatformViewsController.java:631)
E/AndroidRuntime( 6423):  at io.flutter.embedding.engine.FlutterEngine.destroy(FlutterEngine.java:426)
E/AndroidRuntime( 6423):  at com.ryanheise.audioservice.AudioServicePlugin.disposeFlutterEngine(AudioServicePlugin.java:111)
E/AndroidRuntime( 6423):  at com.ryanheise.audioservice.AudioServicePlugin$AudioHandlerInterface.onDestroy(AudioServicePlugin.java:807)
E/AndroidRuntime( 6423):  at com.ryanheise.audioservice.AudioService.onDestroy(AudioService.java:359)
E/AndroidRuntime( 6423):  at android.app.ActivityThread.handleStopService(ActivityThread.java:4819)
E/AndroidRuntime( 6423):  ... 9 more

Expected behavior Closing the app without error.

Screenshots No screenshots needed

Desktop (please complete the following information):

Smartphone (please complete the following information):

Flutter SDK version

[✓] Flutter (Channel stable, 3.0.0, on Linux Mint 20.2 5.4.0-120-generic, locale ru_RU.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[!] Android Studio (not installed)
[✓] VS Code (version 1.68.1)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

Additional context -/-

ryanheise commented 2 years ago

Hi @waplay , this may be a bug in wortise. I tried to track it down, but wortise is unfortunately not open source so I can't take a look without reverse engineering the code. The wortise flutter plugin also doesn't have a GitHub page to report issues. I guess if you are a customer, you can talk to them directly.

Although I can't see how wortise is working under the hood, I can just say that the receiver should be unregistered when the activity is gone. audio_service may still keep the FlutterEngine around beyond this point, though, so if wortise is waiting for the engine to be destroyed before unregistering the receiver, then it is doing the wrong thing.

waplay commented 2 years ago

Thanks @ryanheise . I will try to talk to support Wortise.

waplay commented 2 years ago

Wortise solved the problem on his side. Can be closed.

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs, or use StackOverflow if you need help with just_audio.