MAL73049
MAL73049

Reputation: 63

How to solve Duplicate class java.lang.RuntimeException: Duplicate class com.google.zxing.client

I am currently facing a Duplicate class RuntimeException. In our current use case we are producing an artifact which is using com.journeyapps:zxing-android-embedded. Our client wants to include our artifact but they are getting a RuntimeException during the compilation. The Exception occurs because they are using com.google.zxing which is currently clashing with the journeyapps port of zxing which we are using. Journeyapps did a port of the ZXing Android application as an Android library project, for embedding in an Android application.

Caused by: java.util.concurrent.ExecutionException: java.lang.RuntimeException: Duplicate class com.google.zxing.client.android.camera.CameraConfigurationUtils found in modules android-core-3.3.0.jar (com.google.zxing:android-core:3.3.0) and classes.jar (com.journeyapps:zxing-android-embedded:3.6.0)

Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.
        at com.android.ide.common.workers.ExecutorServiceAdapter.await(ExecutorServiceAdapter.kt:56)
        ... 71 more
Caused by: java.lang.RuntimeException: Duplicate class com.google.zxing.client.android.camera.CameraConfigurationUtils found in modules android-core-3.3.0.jar (com.google.zxing:android-core:3.3.0) and classes.jar (com.journeyapps:zxing-android-embedded:3.6.0)

Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.
        at com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable.run(CheckDuplicateClassesDelegate.kt:132)
        at com.android.ide.common.workers.ExecutorServiceAdapter$submit$submission$1.run(ExecutorServiceAdapter.kt:40)
        ... 72 more

I have tried to exclude the duplicate classes inside the gradle build file. Using the following code and vise versa.

implementation("com.google.zxing:android-core:3.3.0")
implementation("module which includes com.journeyapps:zxing-android-embedded:3.6.6") {
        exclude group: 'com.google.zxing', module: 'android-core'
    }

Without a solution. I even tried to exclude the module inside the configuration. If I do so it is missing during the insertion of the dependencies.

You can reproduce the error using the following code

implementation("com.google.zxing:android-core:3.3.0")
implementation("com.journeyapps:zxing-android-embedded:3.6.0")

As I tried to solve the problem for a lot of hours without a solution, I am very thankful for every advise.

Upvotes: 4

Views: 7144

Answers (5)

Leandro Ariel
Leandro Ariel

Reputation: 1381

Dentro del build.gradle(app) agregar:

android {
    configurations {
        all*.exclude group: 'com.google.zxing'
    }
}

Upvotes: 0

ittradco
ittradco

Reputation: 193

Thanks to your comments I solved the issue like below image

enter image description here

dependencies {
    configurations.all {
        exclude group: 'com.google.zxing'
    }
}

android {
  compileSdkVersion 33
  defaultConfig {
    minSdkVersion 17
    generatedDensities = []
    multiDexEnabled true
    versionCode 1
    versionName "1.0.0"
  }
  aaptOptions {
    additionalParameters "--no-version-vectors"
  }
}

Upvotes: 2

Mohammad Shamsi
Mohammad Shamsi

Reputation: 571

this solve for me

add below code in Android/app/build.gradle file

configurations {
compile.exclude group: 'com.google.zxing'
}

Upvotes: 11

MAL73049
MAL73049

Reputation: 63

We came to the conclusion that we can not exclude the dependencies because their is a naming issue in case of some classes with com.journeyapps:zxing and com.google.zxing.

We ended up migrating our libary from com.journeyapps:zxing to com.google.zxing.

Thanks to PJain for the advise.

Upvotes: 0

PJain
PJain

Reputation: 566

try using this transitive flag maybe this can help you out

implementation("module which includes com.journeyapps:zxing-android-embedded:3.6.6") {
        exclude group: 'com.google.zxing', module: 'android-core'
        transitive = false
    }

Upvotes: 2

Related Questions