Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve Google API advice , program type already present issue?

I am developing a speech recognation application in Android . Using Google Cloud Speech api and Firebase Cloudstore(for DB)

When I build my project , I am gettting following error ::

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

I don't know how to resolve this

My steps
I searched in stackoverflow and found similar issues , but no for my issue in particular

That is , I don't know which packages I need to exclude to resolve dependency conflict

Please help me

My 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
}
like image 707
Lord Commander Avatar asked Nov 07 '22 19:11

Lord Commander


1 Answers

I had the same error and here is how I fixed the problem:
1) Update google services and firebase services to the latest one.
2) If you get a new Gradle conflict error like this:
Error: Program type already present: com.google.type.PostalAddressOrBuilder then exclude it. I did a quick google search by typing com.google.type.PostalAddressOrBuilder and found out what library to exclude. Here is my final code.

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'

    }
like image 154
makkhay gurung Avatar answered Nov 15 '22 00:11

makkhay gurung