嘿我正在尝试将Google Cloud Speech API用于Android,但我收到此错误并且无法绕过它。
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)
我搜索了这个,但找不到解决方案。这是发生错误的代码
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();
}
}
};
以下是MicrophoneStreamRecognizeClient
类的代码段:
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();
}
}
答案 0 :(得分:0)
清理build
文件夹解决了问题。不确定为什么ART有问题,但Dalvik
没有。
运行gradle
清理任务并未完全清除我的构建文件夹。我必须手动完成,但干净可能适用于某些人。
java.lang.VerifyError
可能由于某种原因发生:
一个类尝试扩展声明为final
方法尝试覆盖声明为final
将错误的参数传递给方法
clint = new MicrophoneStreamRecognizeClient(getResources()
.openRawResource(R.raw.credential), Self); //crashes here
我不知道Self
是什么。那可以吗?
试试这个。
synchronized (this) {
MicrophoneStreamRecognizeClient client;
try {
client = new MicrophoneStreamRecognizeClient(getResources().openRawResource(R.raw.credential), Self); //crashes here
client.start();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
因为另一个问题可以!! try / catch块内的同步块!! java.lang.VerifyError
reference
答案 1 :(得分:0)
如果由library differences between runtime and compiling触发了java.lang.VerifyError
,正如@Enamul所建议的那样,那么您可能需要检查com.google.cloud.speech.v1.StreamingRecognizeResponse
和com.google.cloud.speech.v1beta1.StreamingRecognizeResponse
之间的差异。
即便如此,请尝试使用该版本的beta版本。启发您的示例使用测试版。