如何解决Google API建议,程序类型已存在的问题?

时间:2019-03-20 07:41:29

标签: android firebase gradle android-gradle google-speech-api

我正在用Android开发语音识别应用程序。使用Google Cloud Speech API和Firebase Cloudstore(用于数据库)

在构建项目时,我会遵循以下错误::

t

我不知道该如何解决

我的步骤
我在stackoverflow中进行搜索,发现了类似的问题,但对于我的问题却没有找到

也就是说,我不知道需要排除哪些软件包来解决依赖冲突

请帮助我

我的摇篮

Error: Program type already present: com.google.api.Advice$1

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.google.cloud.examples.speechrecognition"
        minSdkVersion 23
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    configurations {
        compile.exclude group: 'com.google.protobuf', module: 'protobuf-lite'

    }
    // exclude files that are not needed from the cloud client libraries
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/INDEX.LIST'
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
// https://mvnrepository.com/artifact/io.grpc/grpc-grpclb
    compile group: 'io.grpc', name: 'grpc-grpclb', version: '1.19.0'

    // https://mvnrepository.com/artifact/io.grpc/grpc-auth
    compile group: 'io.grpc', name: 'grpc-auth', version: '1.19.0'

    // https://mvnrepository.com/artifact/io.grpc/grpc-alts
    compile group: 'io.grpc', name: 'grpc-alts', version: '1.19.0'
// https://mvnrepository.com/artifact/io.grpc/grpc-android
    compile group: 'io.grpc', name: 'grpc-android', version: '1.19.0'

    // add these dependencies for the speech client
    implementation 'io.grpc:grpc-okhttp:1.19.0'
    implementation 'com.google.cloud:google-cloud-speech:0.83.0-beta'

    implementation 'com.google.firebase:firebase-firestore:18.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test:rules:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

task copySecretKey(type: Copy) {
    File secretKey = file "$System.env.GOOGLE_APPLICATION_CREDENTIALS"
    from secretKey.getParent()
    include secretKey.getName()
    into 'src/main/res/raw'
    rename secretKey.getName(), "credential.json"
}
preBuild.dependsOn(copySecretKey)

1 个答案:

答案 0 :(得分:1)

我遇到了相同的错误,这是解决问题的方法:
1)将google服务和firebase服务更新到最新的服务。
2)如果您收到新的Gradle冲突错误,如下所示:
Error: Program type already present: com.google.type.PostalAddressOrBuilder 然后将其排除。我通过输入com.google.type.PostalAddressOrBuilder进行了快速的Google搜索,并找出了要排除的库。这是我的最终代码。

implementation  ('com.google.cloud:google-cloud-translate:1.21.0'){
        exclude group: 'io.grpc', module: 'grpc-all'
        exclude group: 'com.google.protobuf', module: 'protobuf-java'
        exclude group: 'com.google.api-client', module: 'google-api-client-appengine'
        exclude group: 'com.google.api.grpc', module: 'proto-google-common-protos'

    }