Bug: Unsupported Device on Android
nicolocarpignoli opened this issue · 8 comments
Describe the bug
I got "Unsupported Device" on a Huawei Android 11
To Reproduce
Steps to reproduce the behavior:
I reproduced exactly the code from the Readme.
On iOS 12 (iPhone 6) the same code works perfectly.
I added the intent on the Android Manifest and also registered the plugin on MainActivity.java.
Debugging, When I call the "speak" method, I see that "this.speechSynthesis" is null, so I got the error of unsupported device.
Why so?
What can be the reason?
Expected behavior
I expected the APIs to work
Smartphone (please complete the following information):
- Huawei P20
- OS: Android 11
- Chrome 89
It looks like the web API is used and not the actual Android API.
This happens when the plugin is not properly registered in MainActivity.java
.
Which versions of the following packages are used?
@capacitor/cli
@capacitor/android
@capacitor-community/text-to-speech
What does your MainActivity.java
look like?
A working example can be found here: robingenz/capacitor-plugin-demo (Capacitor 3)
Thank for your answer.
This is the MainActivity.java
package com.example.app;
import android.os.Bundle;
import com.getcapacitor.BridgeActivity;
import com.getcapacitor.Plugin;
import com.getcapacitor.community.tts.TextToSpeech;
import java.util.ArrayList;
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initializes the Bridge
this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
// Additional plugins you've installed go here
// Ex: add(TotallyAwesomePlugin.class);
add(TextToSpeech.class);
}});
}
}
Dependencies are:
...
"@capacitor-community/text-to-speech": "0.2.3",
"@capacitor/android": "2.4.7",
"@capacitor/cli": "2.4.7",
...
I'm using Capacitor 2.
This looks right.
Please verify that the capacitor-community-text-to-speech
project is listed in Android Studio.
Example:
If it is not listed there, please run npx cap sync
again.
It is also recommended to clear the cache in Android Studio (File -> Invalidate Caches / Restart...) and run a new Gradle sync (File -> Sync Project with Gradle Files).
Here you can find a workable example using Capacitor 2.4.7: https://github.com/robingenz/capacitor-plugin-demo/tree/41cf6750de0520f6ddfbc3b6a5422c8117177eef
Does it work with this demo app on your device?
Thanks.
All the things you have said I checked and they are good.
But My project does not work and give the same error, while the example works.
Is it possible that the problem relies on the fact that your demo uses Ionic and mine not?
Is this plugin bounded to that?
This plugin only has a dependency on Capacitor and should therefore work without the Ionic framework.
If you create a Minimal, Reproducible Example, I'll test it.
Thanks, you're very, very kind!
I have created the repo keeping all the minimal parts (also with a simple readme). You should be able to run it in seconds.
https://github.com/nicolocarpignoli/tts-mockup
Let me know and thanks again
No problem, I'm happy to help.
The package is imported incorrectly. The used import syntax works only from Capacitor 3.
Wrong (with Capacitor 2):
import { TextToSpeech } from '@capacitor-community/text-to-speech';
Correct (with Capacitor 2):
// Must import the package once to make sure the web support initializes
import '@capacitor-community/text-to-speech';
import { Plugins } from '@capacitor/core';
const { TextToSpeech } = Plugins;
See README.md
from version 0.2.3
: https://github.com/capacitor-community/text-to-speech/tree/v0.2.3#usage
Since I discovered this error directly, I did not test anything further. Please update your code and test it again. Let me know if it still doesn't work.
Oh, it was that! Thank you so, so much :)
Closing!