Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix 'Duplicate classes' in Android Studio

I'm making a barcode scanner application in Android Studio and I use the zxing library for it. The problem if I am adding the library and want to build my project, the 'app:checkDebugDuplicateClasses' step won't work and many 'duplicate classes' errors appear in the console.

I already tried to fix it with thousands of little steps in 'build.gradle' but it all didn't work.

That's my build.gradle file:

    compileSdkVersion 28
    defaultConfig {
        applicationId "eu.lenni.kran"
        minSdkVersion 28
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.journeyapps:zxing-android-embedded:3.4.0'
}

Thats the errors:

org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:129)
    ... 6 more
Caused by: com.android.ide.common.workers.WorkerExecutorException: 1 exception was raised by workers:
java.lang.RuntimeException: Duplicate class android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:23.1.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle found in

and so on...

like image 934
TheRealLenni Avatar asked Jan 01 '26 04:01

TheRealLenni


1 Answers

Use Upgraded Library Version

implementation('com.journeyapps:zxing-android-embedded:3.6.0') { transitive = false }

It is working Perfectly

For more Details:- https://github.com/journeyapps/zxing-android-embedded#adding-aar-dependency-with-gradle

like image 153
Nikunj Paradva Avatar answered Jan 02 '26 18:01

Nikunj Paradva