Duplicate classes in Gradle build, in Android Studio Application

3.2k Views Asked by At

I have been stumped on this problem for hours, I am currently getting a duplicate classes error, when adding this specific dependency.

    implementation 'com.google.apis:google-api-services-vision:v1-rev369-1.23.0'

My App Level Build.gradle file is

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


android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"
    defaultConfig {
        applicationId "com.example.digitaldocs"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true


        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
    implementation 'com.google.android.material:material:1.0.0-beta01'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
    implementation 'androidx.vectordrawable:vectordrawable:1.0.0-beta01'
    implementation 'com.google.firebase:firebase-database:19.3.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.android.support:support-annotations:28.0.0'
    implementation 'com.google.firebase:firebase-ml-vision:24.0.3'

    testImplementation 'junit:junit:4.12'
    implementation 'com.android.support:multidex:1.0.3'
    //noinspection GradleCompatible
    implementation 'com.android.support:support-v4:26.1.0'
    implementation 'com.google.firebase:firebase-auth:19.4.0'
    implementation 'com.google.firebase:firebase-firestore:21.6.0'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
    implementation "androidx.core:core-ktx:+"
    implementation 'com.google.apis:google-api-services-vision:v1-rev369-1.23.0'

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    implementation 'androidx.annotation:annotation:1.1.0'
}
repositories {
    mavenCentral()
}

my project level build.gradle file is

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.4.10'
    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'
        classpath 'com.google.gms:google-services:4.3.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // 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
}

My Stack Trace is as follows

    Duplicate class com.google.common.annotations.Beta found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.annotations.GwtCompatible found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.annotations.GwtIncompatible found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.annotations.VisibleForTesting found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.Absent found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.AbstractIterator found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.AbstractIterator$1 found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.AbstractIterator$State found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.Ascii found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.CaseFormat found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.CaseFormat$1 found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.CaseFormat$2 found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.CaseFormat$3 found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.CaseFormat$4 found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.CaseFormat$5 found in modules jetified-guava-28.1-android.jar (com.google.guava:guava:28.1-android) and jetified-guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
1

There are 1 best solutions below

0
On

Replace this

implementation 'com.google.apis:google-api-services-vision:v1-rev369-1.23.0'

With this

implementation ('com.google.apis:google-api-services-vision:v1-rev369-1.23.0'){
    exclude group:'com.google.guava'
}