'Duplicate class found

I have Duplicate class found error in android studio. This error is because of below line. implementation 'com.google.firebase:firebase-ml-vision-image-label-model:20.0.1'

My App/build.gradle file is under

plugins {
    id 'com.android.application'
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'


android {
    compileSdk 32

    defaultConfig {
        applicationId "com.example.midsemesterassignment"
        minSdk 19
        targetSdk 32
        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
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation platform('com.google.firebase:firebase-bom:29.3.0')


    implementation 'com.google.android.gms:play-services-vision:20.1.1'
    implementation 'com.google.android.gms:play-services-vision-common:19.1.1'
    implementation 'com.google.android.gms:play-services-vision-image-label:18.0.5'
    implementation 'com.google.android.gms:play-services-mlkit-text-recognition:18.0.0'
    implementation 'com.google.firebase:firebase-ml-vision:15.0.0'
    //Duplicate class error due to below import
    implementation 'com.google.firebase:firebase-ml-vision-image-label-model:20.0.1'
    implementation 'com.google.mlkit:barcode-scanning:17.0.2'
    implementation 'com.google.firebase:firebase-core:15.0.2'
    implementation 'com.google.firebase:firebase-database:20.0.4'


    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

}

i also used android.enableJetifier=true to solve it but again get this error

my gradle.properties file is under

org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
android.useAndroidX=true
android.nonTransitiveRClass=true
android.enableJetifier=true

I am using firebase to detect object

i have a button when click on it the image object should be detected code is under

chose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i= new Intent();
                i.setType("image/*");
                i.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(Intent.createChooser(i,"Select images"),121);
            }
        });

 @Override
    protected void onActivityResult(int requestCode, int resultCode,@Nullable Intent data){
        super.onActivityResult(requestCode,resultCode,data);
        if(requestCode==121){
            imageView.setImageURI(data.getData());


            FirebaseVisionImage image;

//            Not working due to duplicate class error and there is no solution of it
            try {


                image = FirebaseVisionImage.fromFilePath(getApplicationContext(), data.getData());
                FirebaseVisionImageLabeler labeler = FirebaseVision.getInstance()
                        .getOnDeviceImageLabeler();

                labeler.processImage(image)
                        .addOnSuccessListener(new OnSuccessListener<List<FirebaseVisionImageLabel>>() {
                            @Override
                            public void onSuccess(List<FirebaseVisionImageLabel> labels) {
                                for (FirebaseVisionImageLabel label: labels) {
                                    String text = label.getText();
                                    String entityId = label.getEntityId();
                                    float confidence = label.getConfidence();
                                    resultTv.append(text+"    "+confidence+"\n");
                                }
                            }
                        })
                        .addOnFailureListener(new OnFailureListener() {
                            @Override
                            public void onFailure(@NonNull Exception e) {
                                // Task failed with an exception
                                // ...
                            }
                        });
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
}


Can someone please help me to solve this problem



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source