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

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

我正在使用 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'

希望对您有所帮助!