capacitor-community/text-to-speech

bug: Runtime crash - NoClassDefFoundError

RouR opened this issue · 5 comments

RouR commented

Plugin version:
"@capacitor-community/text-to-speech": "^3.0.0",
"@capacitor/app": "^5.0.3",
"@ionic/angular": "^7.0.12",

Platform(s):
Tested only on android:
Android 6 - crash
Android 11 - is ok

Current behavior:

Runtime crash:

    let voices = await TextToSpeech.getSupportedVoices();

Logs:

2023-06-09 13:18:48.073 17050-17050 Capacitor/Plugin        my.app               V  To native (Capacitor plugin): callbackId: 117631101, pluginId: TextToSpeech, methodName: getSupportedVoices
2023-06-09 13:18:48.073 17050-17050 Capacitor               my.app               V  callback: 117631101, pluginId: TextToSpeech, methodName: getSupportedVoices, methodData: {}
2023-06-09 13:18:48.077 17050-17050 Capacitor/Plugin        my.app               V  To native (Capacitor plugin): callbackId: 117631102, pluginId: TextToSpeech, methodName: getSupportedVoices
2023-06-09 13:18:48.077 17050-17050 Capacitor               my.app               V  callback: 117631102, pluginId: TextToSpeech, methodName: getSupportedVoices, methodData: {}
2023-06-09 13:18:49.216 17050-17097 art                     my.app               I  Rejecting re-init on previously-failed class java.lang.Class<com.getcapacitor.community.tts.TextToSpeech$$ExternalSyntheticLambda0>
2023-06-09 13:18:49.218 17050-17097 Capacitor               my.app               E  Serious error executing plugin
	java.lang.reflect.InvocationTargetException
		at java.lang.reflect.Method.invoke(Native Method)
		at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138)
		at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:780)
		at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Bridge.java)
		at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(D8$$SyntheticClass)
		at android.os.Handler.handleCallback(Handler.java:739)
		at android.os.Handler.dispatchMessage(Handler.java:95)
		at android.os.Looper.loop(Looper.java:148)
		at android.os.HandlerThread.run(HandlerThread.java:61)
	Caused by: java.lang.NoClassDefFoundError: com.getcapacitor.community.tts.TextToSpeech$$ExternalSyntheticLambda0
		at com.getcapacitor.community.tts.TextToSpeech.getSupportedVoicesOrdered(TextToSpeech.java:125)
		at com.getcapacitor.community.tts.TextToSpeech.getSupportedVoices(TextToSpeech.java:133)
		at com.getcapacitor.community.tts.TextToSpeechPlugin.getSupportedVoices(TextToSpeechPlugin.java:95)
		at java.lang.reflect.Method.invoke(Native Method) 
		at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138) 
		at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:780) 
		at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Bridge.java) 
		at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(D8$$SyntheticClass) 
		at android.os.Handler.handleCallback(Handler.java:739) 
		at android.os.Handler.dispatchMessage(Handler.java:95) 
		at android.os.Looper.loop(Looper.java:148) 
		at android.os.HandlerThread.run(HandlerThread.java:61) 
2023-06-09 13:18:49.233 17050-17097 AndroidRuntime          my.app               E  FATAL EXCEPTION: CapacitorPlugins
	Process: my.app, PID: 17050
	java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
		at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:789)
		at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Bridge.java)
		at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(D8$$SyntheticClass)
		at android.os.Handler.handleCallback(Handler.java:739)
		at android.os.Handler.dispatchMessage(Handler.java:95)
		at android.os.Looper.loop(Looper.java:148)
		at android.os.HandlerThread.run(HandlerThread.java:61)
	Caused by: java.lang.reflect.InvocationTargetException
		at java.lang.reflect.Method.invoke(Native Method)
		at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138)
		at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:780)
		at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Bridge.java) 
		at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(D8$$SyntheticClass) 
		at android.os.Handler.handleCallback(Handler.java:739) 
		at android.os.Handler.dispatchMessage(Handler.java:95) 
		at android.os.Looper.loop(Looper.java:148) 
		at android.os.HandlerThread.run(HandlerThread.java:61) 
	Caused by: java.lang.NoClassDefFoundError: com.getcapacitor.community.tts.TextToSpeech$$ExternalSyntheticLambda0
		at com.getcapacitor.community.tts.TextToSpeech.getSupportedVoicesOrdered(TextToSpeech.java:125)
		at com.getcapacitor.community.tts.TextToSpeech.getSupportedVoices(TextToSpeech.java:133)
		at com.getcapacitor.community.tts.TextToSpeechPlugin.getSupportedVoices(TextToSpeechPlugin.java:95)
		at java.lang.reflect.Method.invoke(Native Method) 
		at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138) 
		at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:780) 
		at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Bridge.java) 
		at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(D8$$SyntheticClass) 
		at android.os.Handler.handleCallback(Handler.java:739) 
		at android.os.Handler.dispatchMessage(Handler.java:95) 
		at android.os.Looper.loop(Looper.java:148) 
		at android.os.HandlerThread.run(HandlerThread.java:61) 
2023-06-09 13:18:49.452 17050-17050 Capacitor/AppPlugin     my.app               V  Notifying listeners for event pause
2023-06-09 13:18:49.453 17050-17050 Capacitor/AppPlugin     my.app               D  No listeners found for event pause
2023-06-09 13:18:49.454 17050-17050 Capacitor               my.app               D  App paused
2023-06-09 13:18:49.745 17050-17050 Capacitor/AppPlugin     my.app               D  Firing change: false
2023-06-09 13:18:49.745 17050-17050 Capacitor/AppPlugin     my.app               V  Notifying listeners for event appStateChange
2023-06-09 13:18:49.746 17050-17050 Capacitor/AppPlugin     my.app               D  No listeners found for event appStateChange
2023-06-09 13:18:49.746 17050-17050 Capacitor               my.app               D  App stopped
2023-06-09 13:18:49.780 17050-17050 Capacitor               my.app               D  App destroyed
2023-06-09 13:18:49.790 17050-17114 chromium                my.app               E  [ERROR:aw_gl_functor.cc(101)] Received unexpected kModeProcessNoContext
2023-06-09 13:18:51.377 17050-17097 Process                 my.app               I  Sending signal. PID: 17050 SIG: 9
---------------------------- PROCESS ENDED (17050) for package my.app ----------------------------

Expected behavior:
Catch the exception and return null or undefined.
Another option is to make the method isAvailable()

Capacitor doctor:

[warn] The bundledWebRuntime configuration option has been deprecated. Can be safely deleted.
   Capacitor Doctor   

Latest Dependencies:

  @capacitor/cli: 5.0.4
  @capacitor/ios: 5.0.4
  @capacitor/core: 5.0.4
  @capacitor/android: 5.0.4

[error] Missing <manifest package=""> attribute in app/src/main

ecc521 commented

@RouR
Does this bug occur in any Android versions above Android 6? Having trouble testing, as Android Studio removed the 6.X emulator Okay I'm just oblivious

RouR commented

I have only two physical devices - Android 6 and Android 11.
I'm not sure that emulator can reproduce it.
Sorry

ecc521 commented

I couldn't get the emulator to work in a reasonable amount of time, as the browser version was way too old and the browser crashed trying to download the updated apk. I'll see if my old Galaxy S5 will work here.

The tts api was added in API 21 (Android 5), so I suspect there is a Java version issue with the Comparator function. A guard should probably be added for that minimum API level (and if this bug isn't an easy fix, perhaps just drop support for choosing a specific voice on Android 6 as well - it's somewhere under 2% of users for most apps now I believe).

ecc521 commented

Okay I can reproduce this bug on a Samsung Galaxy S5 running Android 6
The Comparator is java 8, which isn't used until Android 7.0

ecc521 commented

I'll be submitting a PR to fix this shortly.