java - Google Cloud Speech to Text 错误 : java. lang.NoSuchMethodError: No virtual method build()Lcom/google/protobuf/GeneratedMessageLite;

标签 java android google-speech-api protobuf-java

我正在使用 Google Cloud Speech 发短信。出于某种原因,它只在第一次起作用。之后,这个错误不断出现。我卡住了。

java.lang.NoSuchMethodError: No virtual method build()Lcom/google/protobuf/GeneratedMessageLite; in class Lcom/google/cloud/speech/v1/RecognitionConfig$Builder; or its super classes (declaration of 'com.google.cloud.speech.v1.RecognitionConfig$Builder'

build.gradle 模块应用

apply plugin: 'com.android.application' 
apply plugin: 'com.google.protobuf' 
apply plugin: 'com.jakewharton.butterknife'

ext {
    grpcVersion = '1.4.0' }

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "app.android.com.colconvert"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.2'
    } }

protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc:3.3.0'
    }
    plugins {
        javalite {
            artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
        }
        grpc {
            artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
        }
    }
    generateProtoTasks {
        all().each { task ->
            task.plugins {
                javalite {}
                grpc {
                    // Options added to --grpc_out
                    option 'lite'
                }
            }
        }
    } }


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.intellij:annotations:+@jar'

    implementation 'com.jakewharton:butterknife:10.1.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'

    // gRPC
    implementation "io.grpc:grpc-okhttp:$grpcVersion"
    // implementation "io.grpc:grpc-protobuf-lite:$grpcVersion"
    implementation "io.grpc:grpc-stub:$grpcVersion"
    implementation 'javax.annotation:javax.annotation-api:1.2'
    protobuf 'com.google.protobuf:protobuf-java:3.3.1'
    implementation group: 'com.google.api.grpc', name: 'grpc-google-cloud-speech-v1', version: '0.1.13'
    // OAuth2 for Google API
    implementation('com.google.auth:google-auth-library-oauth2-http:0.7.0') {
        exclude module: 'httpclient'
    }
    implementation 'com.android.support:multidex:1.0.0' 
}

最佳答案

我认为您使用的版本有问题。我建议使用 latest version像下面这样。

implementation group: 'com.google.api.grpc', name: 'grpc-google-cloud-speech-v1', version: '1.10.0'

希望对您有所帮助!

关于java - Google Cloud Speech to Text 错误 : java. lang.NoSuchMethodError: No virtual method build()Lcom/google/protobuf/GeneratedMessageLite;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56875343/

相关文章:

java - 创建从 Android 应用程序的 Assets 文件夹内部到其存储的符号链接(symbolic link)

amazon-s3 - 如何将 S3 存储桶中的音频文件直接提供给 Google 语音转文本

java - 约束布局admob问题

java - 用房间数据库填充微调器

java - java如何重绘动态变量

java - 在 Java 中使用嵌套泛型组织数据(Android)

android - 如何在 Android 和 IOS 应用程序中正确显示来自 MySQL 数据库的选项卡(空格)?

android - 为什么 HierarchyViewer 的 findViewById 如此缓慢?

node.js - 使用 ffmpeg 找不到文件

java - 盲人输入电子邮件和密码的可能方法