Getting ERROR of Duplicate Class Error in Android Studio

  android, class, dependencies

I got an error when build the app :-

Duplicate class com.google.flatbuffers.Constants found in modules
jetified-flatbuffers-java-1.12.0
(com.google.flatbuffers:flatbuffers-java:1.12.0) and
jetified-sceneform-base-1.11.0-runtime
(com.google.ar.sceneform:sceneform-base:1.11.0) Duplicate class
com.google.flatbuffers.FlatBufferBuilder found in modules
jetified-flatbuffers-java-1.12.0
(com.google.flatbuffers:flatbuffers-java:1.12.0) and
jetified-sceneform-base-1.11.0-runtime
(com.google.ar.sceneform:sceneform-base:1.11.0) Duplicate class
com.google.flatbuffers.FlatBufferBuilder$ByteBufferFactory found in
modules jetified-flatbuffers-java-1.12.0
(com.google.flatbuffers:flatbuffers-java:1.12.0) and
jetified-sceneform-base-1.11.0-runtime
(com.google.ar.sceneform:sceneform-base:1.11.0) Duplicate class
com.google.flatbuffers.FlatBufferBuilder$HeapByteBufferFactory found
in modules jetified-flatbuffers-java-1.12.0
(com.google.flatbuffers:flatbuffers-java:1.12.0) and
jetified-sceneform-base-1.11.0-runtime
(com.google.ar.sceneform:sceneform-base:1.11.0) Duplicate class
com.google.flatbuffers.Struct found in modules
jetified-flatbuffers-java-1.12.0
(com.google.flatbuffers:flatbuffers-java:1.12.0) and
jetified-sceneform-base-1.11.0-runtime
(com.google.ar.sceneform:sceneform-base:1.11.0) Duplicate class
com.google.flatbuffers.Table found in modules
jetified-flatbuffers-java-1.12.0
(com.google.flatbuffers:flatbuffers-java:1.12.0) and
jetified-sceneform-base-1.11.0-runtime
(com.google.ar.sceneform:sceneform-base:1.11.0) Duplicate class
com.google.flatbuffers.Utf8 found in modules
jetified-flatbuffers-java-1.12.0
(com.google.flatbuffers:flatbuffers-java:1.12.0) and
jetified-sceneform-base-1.11.0-runtime
(com.google.ar.sceneform:sceneform-base:1.11.0) Duplicate class
com.google.flatbuffers.Utf8Safe found in modules
jetified-flatbuffers-java-1.12.0
(com.google.flatbuffers:flatbuffers-java:1.12.0) and
jetified-sceneform-base-1.11.0-runtime
(com.google.ar.sceneform:sceneform-base:1.11.0)

Go to the documentation to learn how to Fix dependency resolution
errors.

my build/gradle(project):-

buildscript {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.1'
        classpath 'com.google.gms:google-services:4.3.8'
        classpath 'com.google.ar.sceneform:plugin:1.11.0'

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

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


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

build/gradle(module):

plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
    id 'com.google.ar.sceneform.plugin'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.example.kiddyum"
        minSdkVersion 26
        targetSdkVersion 30
        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
    }
    sourceSets {
        main {
            jni {
                srcDirs 'srcmainjni', 'srcmainjnilibs'
            }
        }
    }

    aaptOptions {
        noCompress "tflite"
        noCompress "lite"
    }
    buildFeatures {
        mlModelBinding true
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'com.google.firebase:firebase-database:20.0.0'
    implementation project(path: ':openCVLibrary3413')
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.19'

    //ARSceneform
    //implementation("com.gorisse.thomas.sceneform:sceneform:version")
    //implementation 'com.github.ThomasGorisse.sceneform-android-sdk:sceneform:-SNAPSHOT'
    implementation 'com.google.ar:core:1.11.0'
    implementation 'com.google.ar.sceneform.ux:sceneform-ux:1.11.0'
    implementation 'com.google.ar.sceneform:core:1.11.0'
    implementation 'com.google.ar.sceneform:animation:1.11.0'

    implementation 'org.tensorflow:tensorflow-lite-metadata:0.1.0-rc1'
    implementation 'org.tensorflow:tensorflow-lite-gpu:2.2.0'
    implementation 'org.tensorflow:tensorflow-lite-support:0.1.0'
    implementation 'org.tensorflow:tensorflow-lite-task-vision:0.1.0'
    implementation 'org.tensorflow:tensorflow-lite-task-text:0.1.0'
}

and in my gradle properties already have:

android.useAndroidX=true
android.enableJetifier=true 

did anyone know how to fix this? thank you in advanced.

Source: Android Questions

One Reply to “Getting ERROR of Duplicate Class Error in Android Studio”

LEAVE A COMMENT