question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android hot reload cause crash

See original GitHub issue

The TrackPlayerPlugin and the FlautoPlayerPlugin share a common slot array.

If you do a hot reload the array is not cleared out. The result is that when you restart the slots are not reset and you can get a class cast exception (as a given slot could contain a Track or a Fluato) plugin.

Whilst this is not a problem for running code it will cause problems and confusing during development. We have a couple of options.

  1. separate the slot arrays so each plugin has its own.
  2. clean up the slot arrays when a hot reload occurs.
  • I have some code in Playbar that can detect a hot reload however there is no code in the plugins to free slots (the freeSlot method exists but is never called). I thought that onDetachedFromEngine from engine in Flauto.java might be the place to do this but I have no experience with plugins.

To reproduce this problem: Play Asset with OS Media Player off hot reload Play Asset with OS Media Player on.

This problem can be reproduced on the dev branch code however I believe that it will be a problem in the current production release.


I/flutter (23913): Loading starting
I/flutter (23913): Calling startPlayer
I/flutter (23913): regisetered Proxy: 1065489832
I/flutter (23913): initialise called Proxy: 1065489832
I/flutter (23913): #################SpinKit rendered###################
E/MethodChannel#com.dooboolab.flutter_sound_track_player(23913): Failed to handle method call
E/MethodChannel#com.dooboolab.flutter_sound_track_player(23913): java.lang.ClassCastException: com.dooboolab.fluttersound.FlutterSoundPlayer cannot be cast to com.dooboolab.fluttersound.TrackPlayer
E/MethodChannel#com.dooboolab.flutter_sound_track_player(23913): 	at com.dooboolab.fluttersound.TrackPlayerPlugin.onMethodCall(TrackPlayer.java:132)
E/MethodChannel#com.dooboolab.flutter_sound_track_player(23913): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:231)
E/MethodChannel#com.dooboolab.flutter_sound_track_player(23913): 	at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:93)
E/MethodChannel#com.dooboolab.flutter_sound_track_player(23913): 	at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:642)
E/MethodChannel#com.dooboolab.flutter_sound_track_player(23913): 	at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#com.dooboolab.flutter_sound_track_player(23913): 	at android.os.MessageQueue.next(MessageQueue.java:336)
E/MethodChannel#com.dooboolab.flutter_sound_track_player(23913): 	at android.os.Looper.loop(Looper.java:174)
E/MethodChannel#com.dooboolab.flutter_sound_track_player(23913): 	at android.app.ActivityThread.main(ActivityThread.java:7356)
E/MethodChannel#com.dooboolab.flutter_sound_track_player(23913): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#com.dooboolab.flutter_sound_track_player(23913): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/MethodChannel#com.dooboolab.flutter_sound_track_player(23913): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
bsuttoncommented, Apr 19, 2020

I think there is perhaps an argument for a single plugin which then routes calls to the appropriate class.

At the very least I think we should combine the trackplayer and soundplayer into a single plug. I can’t see any obvious reason why these are separate (unless there is some aspect I’ve missed). Tracker already extends soundplayer. A singular class would make the plugin easier to work with.

On Sun, 19 Apr 2020 at 19:58, Larpoux notifications@github.com wrote:

My plan was to use the same slot array, even with RecordPlayer. Classes RecordPlayer, TrackPlayer, and FlutterSoundPlayer would inherit from a common base class which will do the mux on its flutter channel. No duplicated code anymore.

But if this is a problem with hot reload we can reconsider that.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dooboolab/flutter_sound/issues/304#issuecomment-616091776, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG32OCZTUXMGHII6WDVTFDRNLDLNANCNFSM4MLRETTA .

0reactions
Larpouxcommented, Feb 11, 2021

Fixed in Flutter Sound release 7.6.3

Read more comments on GitHub >

github_iconTop Results From Across the Web

Crash while hot-reloading · Issue #40361 · flutter/flutter - GitHub
This is the console output in Android Studio just after the crash. Initializing hot reload... Syncing files to device Pixel 2 XL.
Read more >
Flutter app crashes on hot restart only on iOS Simulator
After two days of debugging I have just found out it was caused by one of my dependencies. It is firebase_auth package version...
Read more >
MAUI Android App crashes with Hot Reload enabled on ...
When running on Android Emulator (Pixel 2 R.11.0 - API 30 - x86), if Hot Reload is enabled, the app starts, show the...
Read more >
Manually reloading your Flutter web app causes it to crash/get ...
It either crashes or never finish reloading.
Read more >
Crashes - Android Developers
An Android app crashes whenever there's an unexpected exit caused by an unhandled exception or signal. An app that is written using Java...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found