flutter_tts icon indicating copy to clipboard operation
flutter_tts copied to clipboard

Build in release mode doesn't work

Open jporrinoclapps opened this issue 4 years ago • 9 comments

🐛 Bug Report

When I build my app in debug mode everything works OK. But, in release mode, although the tts engine is set to default (com.google.android.tts) correctly, the getLanguages method returns an empty array and the isLanguageAvailable always returns false. Also, the app crashes without any further call to any other methods (this last thing I think is related to the set of tts engine and not the languages).

Logs:

Installing build/app/outputs/flutter-apk/app.apk...
I/flutter (26524): Tts Init State: LOADING
I/flutter (26524): Db Init State: LOADING
I/flutter (26524): com.google.android.tts
I/flutter (26524): []
I/flutter (26524): Tts Init State: ERROR
I/flutter (26524): Language not available
I/flutter (26524): Db Init State: SUCCESS
E/AndroidRuntime(26524): FATAL EXCEPTION: main
E/AndroidRuntime(26524): Process: xyz.clapps.flutter_tts, PID: 26524
E/AndroidRuntime(26524): java.lang.IllegalStateException: Reply already submitted
E/AndroidRuntime(26524): 	at io.flutter.embedding.engine.e.b$a.a(Unknown Source:35)
E/AndroidRuntime(26524): 	at d.a.c.a.j$a$a.a(Unknown Source:14)
E/AndroidRuntime(26524): 	at b.c.a.a.r(Unknown Source:6)
E/AndroidRuntime(26524): 	at b.c.a.a.a(Unknown Source:582)
E/AndroidRuntime(26524): 	at b.c.a.a$e.run(Unknown Source:6)
E/AndroidRuntime(26524): 	at b.c.a.a$d.onInit(Unknown Source:110)
E/AndroidRuntime(26524): 	at android.speech.tts.TextToSpeech.dispatchOnInit(TextToSpeech.java:831)
E/AndroidRuntime(26524): 	at android.speech.tts.TextToSpeech.access$1500(TextToSpeech.java:63)
E/AndroidRuntime(26524): 	at android.speech.tts.TextToSpeech$Connection$SetupConnectionAsyncTask.onPostExecute(TextToSpeech.java:2222)
E/AndroidRuntime(26524): 	at android.speech.tts.TextToSpeech$Connection$SetupConnectionAsyncTask.onPostExecute(TextToSpeech.java:2177)
E/AndroidRuntime(26524): 	at android.os.AsyncTask.finish(AsyncTask.java:695)
E/AndroidRuntime(26524): 	at android.os.AsyncTask.access$600(AsyncTask.java:180)
E/AndroidRuntime(26524): 	at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:712)
E/AndroidRuntime(26524): 	at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(26524): 	at android.os.Looper.loop(Looper.java:193)
E/AndroidRuntime(26524): 	at android.app.ActivityThread.main(ActivityThread.java:6923)
E/AndroidRuntime(26524): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(26524): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/AndroidRuntime(26524): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)

Doctor:

[✓] Flutter (Channel stable, 2.2.3, on macOS 11.5.1 20G80 darwin-x64, locale en-AR)
    • Flutter version 2.2.3 at /Users/jporrino/Downloads/flutter
    • Framework revision f4abaa0735 (4 weeks ago), 2021-07-01 12:46:11 -0700
    • Engine revision 241c87ad80
    • Dart version 2.13.4

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/jporrino/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.5.1, Build version 12E507
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)

[✓] Connected device (2 available)
    • moto g 6 (mobile) • ZY322P3D75 • android-arm    • Android 9 (API 28)
    • Chrome (web)      • chrome     • web-javascript • Google Chrome 92.0.4515.107

• No issues found!

Expected behavior

App behavior should not change depending on build mode

Configuration

Added the following code as instructed but noticed no change. Also, the gradle's minSdkVersion is set to 21.

<manifest ... >
...
   <queries>
       <intent>
           <action android:name="TextToSpeech.Engine.INTENT_ACTION_TTS_SERVICE" />
       </intent>
   </queries>
...
</manifest>

Version: ^3.2.1

Platform:

  • [ ] :iphone: iOS
  • [X] :robot: Android

jporrinoclapps avatar Jul 28 '21 18:07 jporrinoclapps

@jporrinoclapps I'm already looking into the issue as it's related to the same error mentioned in #260

dlutton avatar Jul 28 '21 19:07 dlutton

@dlutton I read the FlutterTtsPlugin.java to further understand how the package works and how I could solve at least my problem. Also, to get rid of other variables in the equation, I continued my testing using your example code and running it in release mode.

Turns out I didn't need to use the setEngine method, as I am not going to change the tts engine from its default value, and an instance of TextToSpeech is already created during the package initialization (in the call to initInstance made after attachment to the FlutterEngine). I found that, as long as I don't use the setEngine method, the release mode build works just fine.

Also, the crash did not occur if I call the method speak before calling the method setEngine.

I hope this information helps you to figure out this strange behavior.

jporrinoclapps avatar Jul 29 '21 14:07 jporrinoclapps

@jporrinoclapps that is very helpful thank you.

dlutton avatar Jul 29 '21 19:07 dlutton

If the exact same thing happens to me before the realease is released, it breaks when performing a setEngine

dqtorres avatar Aug 21 '21 11:08 dqtorres

@dqtorres are you possibly setting it to an engine that isn't installed on the device? By default it uses the Google TTS engine, so the setEngine method isn't necessary unless you plan on setting it to a different engine. You can call the method getEngines to see the options available to you.

dlutton avatar Aug 23 '21 18:08 dlutton

@dlutton Thanks, if the setEngine method works correctly but only in debug, when the application is passed to release mode it gives the exception reported, all the devices work fine but only in debug. My goal is to use another tts engine and I get it to work on the device but when the realease is created on the same device by making the setEngines break, the getEngines method has previously been called to see the engines available on the device, it is a very error rare that it is not appreciated unless the release is created, thanks

dqtorres avatar Aug 23 '21 18:08 dqtorres

@dqtorres do you receive the same error as mentioned by @jporrinoclapps?

dlutton avatar Aug 23 '21 19:08 dlutton

@dqtorres After setting engine, it takes some time to fully initialize tts. Can you test example app with Future.delayed(Duration(seconds: 1)); right after setEngine?

Syutkin avatar Aug 23 '21 21:08 Syutkin

@Syutkin @dlutton You are right, the release mode is too fast, I did what you said and fantastic it already works, but after initialization, Thank you very much again

initTts() async { flutterTts = FlutterTts(); await Future.delayed(Duration (seconds: 1));

dqtorres avatar Aug 23 '21 22:08 dqtorres