Fix Android Crash:
- FIX 1: Iterate over a copy of the list to avoid ConcurrentModificationException.
- FIX 2: Only reply once per request to avoid "Reply already submitted" crash.
Exception java.util.ConcurrentModificationException: at java.util.ArrayList$Itr.checkForComodification (ArrayList.java:1111) at java.util.ArrayList$Itr.next (ArrayList.java:1064) at com.tundralabs.fluttertts.FlutterTtsPlugin.onInitListener$lambda$3 (FlutterTtsPlugin.java:221) at android.speech.tts.TextToSpeech.lambda$dispatchOnInit$0 (TextToSpeech.java:934) at android.speech.tts.TextToSpeech.$r8$lambda$goj8UKjdOAM21kdYLRXRNDpSxxI (Unknown Source) at android.speech.tts.TextToSpeech$$ExternalSyntheticLambda1.run (Unknown Source:4) at android.speech.tts.TextToSpeech.dispatchOnInit (TextToSpeech.java:943) at android.speech.tts.TextToSpeech.-$$Nest$mdispatchOnInit (Unknown Source) at android.speech.tts.TextToSpeech$Connection$SetupConnectionAsyncTask.onPostExecute (TextToSpeech.java:2324) at android.speech.tts.TextToSpeech$Connection$SetupConnectionAsyncTask.onPostExecute (TextToSpeech.java:2284) at android.os.AsyncTask.finish (AsyncTask.java:771) at android.os.AsyncTask.-$$Nest$mfinish (Unknown Source) at android.os.AsyncTask$InternalHandler.handleMessage (AsyncTask.java:788) at android.os.Handler.dispatchMessage (Handler.java:106) at android.os.Looper.loopOnce (Looper.java:230) at android.os.Looper.loop (Looper.java:319) at android.app.ActivityThread.main (ActivityThread.java:8919) at java.lang.reflect.Method.invoke at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:578) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1103)
Exception java.lang.IllegalStateException: Reply already submitted at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply (DartMessenger.java:431) at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success (MethodChannel.java:272) at com.tundralabs.fluttertts.FlutterTtsPlugin.onInitListener$lambda$3 (FlutterTtsPlugin.java:240) at android.speech.tts.TextToSpeech.lambda$dispatchOnInit$0 (TextToSpeech.java:934) at android.speech.tts.TextToSpeech.$r8$lambda$goj8UKjdOAM21kdYLRXRNDpSxxI (Unknown Source) at android.speech.tts.TextToSpeech$$ExternalSyntheticLambda1.run (Unknown Source:4) at android.speech.tts.TextToSpeech.dispatchOnInit (TextToSpeech.java:943) at android.speech.tts.TextToSpeech.-$$Nest$mdispatchOnInit (Unknown Source) at android.speech.tts.TextToSpeech$Connection$SetupConnectionAsyncTask.onPostExecute (TextToSpeech.java:2324) at android.speech.tts.TextToSpeech$Connection$SetupConnectionAsyncTask.onPostExecute (TextToSpeech.java:2284) at android.os.AsyncTask.finish (AsyncTask.java:771) at android.os.AsyncTask.-$$Nest$mfinish (Unknown Source) at android.os.AsyncTask$InternalHandler.handleMessage (AsyncTask.java:788) at android.os.Handler.dispatchMessage (Handler.java:106) at android.os.Looper.loopOnce (Looper.java:230) at android.os.Looper.loop (Looper.java:319) at android.app.ActivityThread.main (ActivityThread.java:8919) at java.lang.reflect.Method.invoke at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:578) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1103)
@dlutton please review, i tested in production and it's working great
@hsangtini , does the PR in https://github.com/dlutton/flutter_tts/pull/594 also solve your issue? I need to determine which solution fits best here.
I don’t know about that PR, but with my PR it’s working well in production. All crashes are gone.