Hey I am trying to use Google Cloud Speech API into Android but I am getting this error and am unable to get around it.
java.lang.VerifyError: Verifier rejected class com.google.cloud.speech.v1
.StreamingRecognizeResponse due to bad method java.lang.Object com.google
.cloud.speech.v1.StreamingRecognizeResponse.dynamicMethod(com.google.protobuf
.GeneratedMessageLite$MethodToInvoke, java.lang.Object, java.lang.Object)
(declaration of 'com.google.cloud.speech.v1.StreamingRecognizeResponse'
appears in /data/app/com.curieo.podcast-1/base.apk:classes65.dex)
at com.google.cloud.speech.v1.StreamingRecognizeResponse.getDefaultInstance(StreamingRecognizeResponse.java:1095)
at com.google.cloud.speech.v1.SpeechGrpc.<clinit>(SpeechGrpc.java:67)
at com.curieo.podcast.ui.fragment.dates.googlecloud.StreamingRecognizeClient.<init>(StreamingRecognizeClient.java:57)
at com.curieo.podcast.ui.fragment.dates.googlecloud.MicrophoneStreamRecognizeClient.<init>(MicrophoneStreamRecognizeClient.java:54)
at com.curieo.podcast.ui.fragment.dates.RecordFragment$1.run(RecordFragment.java:112)
I searched for this but couldn't find a solution. here is the code where error occurs
private Thread runner = new Thread() {
public void run() {
try {
MicrophoneStreamRecognizeClient client;
synchronized (this) {
try {
client = new MicrophoneStreamRecognizeClient(getResources().openRawResource(R.raw.credential), Self); //crashes here
client.start();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
};
Here is the code snippet of MicrophoneStreamRecognizeClient
class:
public class MicrophoneStreamRecognizeClient {
private String host = "speech.googleapis.com";
private Integer port = 443;
private ManagedChannel channel;
private StreamingRecognizeClient client;
private final List<String> OAUTH2_SCOPES = Arrays.asList("https://www.googleapis.com/auth/cloud-platform");
/**
*
* @param authorizationFile
* @param host
* @param port
* @return
* @throws IOException
*/
private ManagedChannel createChannel(InputStream authorizationFile, String host, int port) throws IOException {
GoogleCredentials creds = GoogleCredentials.fromStream(authorizationFile);
creds = creds.createScoped(OAUTH2_SCOPES);
return ManagedChannelBuilder.forAddress(host, port)
.intercept(new ClientAuthInterceptor(creds, Executors.newSingleThreadExecutor()))
.build();
}
/**
*
* @param autorizationFile
* @throws IOException
*/
public MicrophoneStreamRecognizeClient(InputStream autorizationFile, IResults screen) throws IOException {
channel = createChannel(autorizationFile, host, port);
client = new StreamingRecognizeClient(channel, screen);
}
/**
*
* @throws IOException
* @throws InterruptedException
*/
public void start() throws IOException, InterruptedException {
client.recognize();
}
/**
*
* @throws InterruptedException
*/
public void stop() throws InterruptedException {
client.shutdown();
}
}