Gradle Build failed with duplicate classes from two external aar file

Hello,

How do I resolve “Duplicate class” error during the build?

I’m using Android Studio to build a project that has two different jar library but on trying to build the project, I am getting this error:

Duplicate class com.imagealgorithmlab.barcode.DecodeEngine found in modules jetified-app-lib-one-release-runtime (:app-lib-one-release:) and jetified-app-lib-two-runtime (:app-lib-two:)
How do I deal with this?

NB: I tried different ways to fix this issue but they all failed

Fixes like
exclude group: 'com.imagealgorithmlab.barcode', module: 'app-lib-one-release'
and

    configurations {
        all*.exclude group: 'com.imagealgorithmlab.barcode', module: 'app-lib-one-release'
}