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

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

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

当我构建项目时,出现以下错误::

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

我不知道如何解决这个问题

我的脚步
我在 stackoverflow 中搜索并发现了类似的问题,但没有特别针对我的问题

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

请帮助我

我的 Gradle

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)
<小时/>
buildscript {
    ext.kotlin_version = '1.3.21'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.2.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

最佳答案

我遇到了同样的错误,这是我解决问题的方法:
1) 将 google 服务和 firebase 服务更新到最新。
2) 如果您收到如下新的 Gradle 冲突错误:
错误:程序类型已存在:com.google.type.PostalAddressOrBuilder 然后将其排除。我通过输入 com.google.type.PostalAddressOrBuilder 进行了快速谷歌搜索,并找到了要排除的库。这是我的最终代码。

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'

    }

关于android - 如何解决 Google API 建议、程序类型已存在的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55255705/

相关文章:

android - 没有导航和状态栏的全屏

java - 使用 request.getParameter 请求不同的参数

javascript - Firebase RememberMe 功能

android - Gradle项目同步失败,如何解决?

java - 创建一个 Spring Boot 应用程序,但无法让 @autowired 工作

android - 我总是收到 1 台设备的不同注册 ID

java - Android 如何将.raw数据转换为.mp3文件?

Firebase Analytics 空用户 ID

ios - 使用适用于 iOS 的 firebase 验证电子邮件

android - Kotlin 崩溃无法将提供的符号转换为 Dependency 类型的对象 : org. jetbrains.kotlin.gradle.dsl.KotlinProjectExtension_Decorated