Duplicate class in build.gradle file - android

I have included following dependencies in build.gradle file. I get the following errors. How to fix them.I have included following dependencies in build.gradle file. I get the following errors. How to fix them.I have included following dependencies in build.gradle file. I get the following errors. How to fix them.I have included following dependencies in build.gradle file. I get the following errors. How to fix them.I have included following dependencies in build.gradle file. I get the following errors. How to fix them.I have included following dependencies in build.gradle file. I get the following errors. How to fix them.
build.gradle:
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.example.testimageuploadhttp"
minSdkVersion 21
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
}
}
def butterKnifeVersion = "8.4.0"
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.jakewharton:butterknife:${butterKnifeVersion}"
annotationProcessor "com.jakewharton:butterknife-compiler:${butterKnifeVersion}"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.annotation:annotation:1.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:4.10'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
//implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
//noinspection DuplicatePlatformClasses,DuplicatePlatformClasses
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
//Volley Library - You need to add this line
implementation 'com.mcxiaoke.volley:library-aar:1.0.0'
//Add this line
implementation 'net.gotev:uploadservice:3.4'
}
error:
Duplicate class org.hamcrest.BaseDescription found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.BaseMatcher found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.CoreMatchers found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.Description found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.Factory found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.Matcher found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.SelfDescribing found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.StringDescription found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.AllOf found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.AnyOf found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.DescribedAs found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.Is found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsAnything found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsEqual found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsInstanceOf found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsNot found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsNull found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsSame found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.internal.ArrayIterator found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.internal.SelfDescribingValue found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.internal.SelfDescribingValueIterator found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Go to the documentation to learn how to Fix dependency resolution errors.
testImplementation 'junit:junit:4.+'
testImplementation 'junit:junit:4.12'
are duplicated, but it is not because of that. I tried commenting out 1. It happens only when I add
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
else things compile fine.

The problem is that the org.hamcrest:hamcrest-core: classes are bundled in Junit also .So to fix the problem follow these steps:---->
----> 1) Click on build and clean the project
clean project
----> 2) add code in buid.gradle
configurations.all {
resolutionStrategy.dependencySubstitution {
substitute module('org.hamcrest:hamcrest-core:1.1') with module('junit:junit:4.10')
}
}
So for anyone same problem to fix but can't exclude JUnit.
Well the solution is very pretty simple but very strange

You have duplicated your dependencies. Entries:
testImplementation 'junit:junit:4.+'
testImplementation 'junit:junit:4.12'
Are pointing to the same library

Related

Android Studio showing Duplicate class found

When generating release build android studio throwing below errors. Which i am not able to resolve. I tried many way which related issue mentioned but didn't succeed.
Duplicate class com.google.android.gms.internal.measurement.zzhx found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzmz found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.internal.measurement.zzna found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.internal.measurement.zznb found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.internal.measurement.zznc found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.internal.measurement.zznd found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.measurement.internal.zzga found in modules jetified-play-services-measurement-19.0.0-runtime (com.google.android.gms:play-services-measurement:19.0.0) and jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2)
Duplicate class com.google.android.gms.measurement.internal.zzhe found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.measurement.internal.zzhf found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.measurement.internal.zzhg found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.measurement.internal.zzhh found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.measurement.internal.zzhi found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.measurement.internal.zzhj found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.measurement.internal.zzio found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
Duplicate class com.google.android.gms.measurement.internal.zzit found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-19.0.0-runtime (com.google.android.gms:play-services-measurement-impl:19.0.0)
I also added android.useAndroidX=true android.enableJetifier=true inside gradle.properties file.
My build.gradle file looks like below
apply plugin: 'com.android.application'
android {
namespace 'com.pp.prescriptionpatriot'
compileSdkVersion 32
defaultConfig {
applicationId "com.pp.prescriptionpatriot"
minSdkVersion 29
targetSdkVersion 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
flatDir{
dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
}
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
// Branch: required for all Android apps
implementation 'io.branch.sdk.android:library:5.2.3'
// Branch: required if your app is in the Google Play Store (tip: avoid using bundled play services libs)
implementation 'com.google.firebase:firebase-appindexing:20.0.0' // App indexing
implementation 'com.google.android.gms:play-services-ads:21.2.0' // GAID matching
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation project(':capacitor-android')
testImplementation "junit:junit:4.13.2"
androidTestImplementation "androidx.test.ext:junit:1.1.3"
androidTestImplementation "androidx.test.espresso:espresso-core:3.4.0"
implementation project(':capacitor-cordova-android-plugins')
implementation 'com.android.support:multidex:1.0.3'
//implementation 'com.google.firebase:firebase-appindexing:19.1.0'
//implementation 'androidx.work:work-runtime:2.7.1'
}
apply from: 'capacitor.build.gradle'
try {
def servicesJSON = file('google-services.json')
if (servicesJSON.text) {
apply plugin: 'com.google.gms.google-services'
}
} catch(Exception e) {
logger.warn("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
}
I fixed this replacing below implementation as per #VineshChauhan comment.
From
implementation 'com.google.android.gms:play-services-ads:21.2.0'
To
implementation 'com.google.android.gms:play-services-ads:20.4.0'
In your gradle.properties file, Add below line then rebuild your project.
android.enableJetifier=true

Implementation of library giving duplicate error

im trying to implement the 'com.github.barteksc:android-pdf-viewer:2.8.2' into my project and i am able to sync the gradle files but when i try to start the app it gives me this error
Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.5.0-
runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.os.IResultReceiver found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.os.ResultReceiver found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.os.ResultReceiver$1 found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Go to the documentation to learn how to Fix dependency resolution errors
i do not get why i will post my build.gradle below
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.jenson.resumeapp"
minSdkVersion 19
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
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
i do not seem to find anything on this that works?
Add these lines in gradle.properties file
android.useAndroidX = true
android.enableJetifier = true
I was running into the same issue when I was implementing :
com.github.shts:StoriesProgressView:3.0.0
The problem, in my case at least, was that StoriesProgessView dependency was retrieving the same class from com.android.support:support-compat which is now already present in the androidx core package, causing the conflict to rise up.
This is how I went about it:
By checking out the Dependency tree, I found out that the StoriesProgressView was bringing in these dependencies, to remove those dependencies, I added the exlusion rule to the dependency like so:
implementation ('com.github.shts:StoriesProgressView:3.0.0') {
exclude group: "com.android.support", module: "support-compat"
exclude group: "com.android.support", module: "support-media-compat"
}
this stopped pulling the classes from the old package.
In your case though, there doesn't seem to be any third-party dependency so probably following Malik Ali's answer should suffice. If it doesn't, give this one a go!
Add this line in gradle.properties
android.enableJetifier = true

Can't resolve "Duplicate Class com.google.android.gms.internal.vision.zzdt found in module" error,

I saw a similar question asked in here but the solution didn't help me and the error is still same. I tried to make new project, but the error is still the same and I don't what's bugging! Please help me with this error, I can't deploy my app just because of this error.
Here is the error log:
Duplicate class com.google.android.gms.internal.vision.zzdt found in modules jetified-play-services-vision-common-19.1.0-runtime (com.google.android.gms:play-services-vision-common:19.1.0) and jetified-play-services-vision-image-labeling-internal-16.0.0-runtime (com.google.android.gms:play-services-vision-image-labeling-internal:16.0.0)
Duplicate class com.google.android.gms.internal.vision.zze found in modules jetified-play-services-vision-20.0.0-runtime (com.google.android.gms:play-services-vision:20.0.0) and jetified-play-services-vision-common-19.1.0-runtime (com.google.android.gms:play-services-vision-common:19.1.0)
Duplicate class com.google.android.gms.internal.vision.zzf found in modules jetified-play-services-vision-20.0.0-runtime (com.google.android.gms:play-services-vision:20.0.0) and jetified-play-services-vision-common-19.1.0-runtime (com.google.android.gms:play-services-vision-common:19.1.0)
Duplicate class com.google.android.gms.internal.vision.zzg found in modules jetified-play-services-vision-20.0.0-runtime (com.google.android.gms:play-services-vision:20.0.0) and jetified-play-services-vision-common-19.1.0-runtime (com.google.android.gms:play-services-vision-common:19.1.0)
Duplicate class com.google.android.gms.internal.vision.zzh found in modules jetified-play-services-vision-20.0.0-runtime (com.google.android.gms:play-services-vision:20.0.0) and jetified-play-services-vision-common-19.1.0-runtime (com.google.android.gms:play-services-vision-common:19.1.0)
Duplicate class com.google.android.gms.internal.vision.zzi found in modules jetified-play-services-vision-20.0.0-runtime (com.google.android.gms:play-services-vision:20.0.0) and jetified-play-services-vision-common-19.1.0-runtime (com.google.android.gms:play-services-vision-common:19.1.0)
Duplicate class com.google.android.gms.internal.vision.zzs found in modules jetified-play-services-vision-common-19.1.0-runtime (com.google.android.gms:play-services-vision-common:19.1.0) and jetified-play-services-vision-image-labeling-internal-16.0.0-runtime (com.google.android.gms:play-services-vision-image-labeling-internal:16.0.0)
Duplicate class com.google.android.gms.internal.vision.zzt found in modules jetified-play-services-vision-common-19.1.0-runtime (com.google.android.gms:play-services-vision-common:19.1.0) and jetified-play-services-vision-image-labeling-internal-16.0.0-runtime (com.google.android.gms:play-services-vision-image-labeling-internal:16.0.0)
Duplicate class com.google.android.gms.internal.vision.zzu found in modules jetified-play-services-vision-common-19.1.0-runtime (com.google.android.gms:play-services-vision-common:19.1.0) and jetified-play-services-vision-image-labeling-internal-16.0.0-runtime (com.google.android.gms:play-services-vision-image-labeling-internal:16.0.0)
Duplicate class com.google.android.gms.internal.vision.zzv found in modules jetified-play-services-vision-20.0.0-runtime (com.google.android.gms:play-services-vision:20.0.0) and jetified-play-services-vision-common-19.1.0-runtime (com.google.android.gms:play-services-vision-common:19.1.0)
Duplicate class com.google.android.gms.internal.vision.zzw found in modules jetified-play-services-vision-20.0.0-runtime (com.google.android.gms:play-services-vision:20.0.0) and jetified-play-services-vision-common-19.1.0-runtime (com.google.android.gms:play-services-vision-common:19.1.0)
Go to the documentation to learn how to Fix dependency resolution errors.
Here is my build.gradle(:app) file
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.finalapp"
minSdkVersion 21
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
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.firebase:firebase-ml-vision:24.1.0'
implementation 'com.google.firebase:firebase-ml-vision-image-label-model:20.0.2'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
and here is my build.gradle(Final App) file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Lower the version of dependency from 24.1.0 to 24.0.0
implementation 'com.google.firebase:firebase-ml-vision:24.0.0'

Duplicate class com.google.common found in modules guava error after migrating to Androidx

This is my build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.app"
multiDexEnabled true
minSdkVersion 26
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/INDEX.LIST'
}
}
configurations {
all*.exclude group: 'com.google.guava', module: 'listenablefuture'
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.facebook.shimmer:shimmer:0.2.0'
implementation 'androidx.multidex:multidex:2.0.0'
testImplementation 'junit:junit:4.12'
implementation 'com.victor:lib:1.0.4'
implementation 'com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1'
implementation 'net.gotev:speech:1.3.1'
implementation files('libs/YouTubeAndroidPlayerApi.jar')
implementation 'com.facebook.fresco:fresco:1.3.0'
implementation 'com.haozhang.libary:android-animated-recording-view:1.0'
implementation 'com.github.arimorty:floatingsearchview:2.1.1'
implementation 'com.google.apis:google-api-services-youtube:v3-rev204-1.23.0'
implementation 'com.shawnlin:number-picker:2.4.6'
implementation 'com.unstoppable:submitbutton:1.1.3'
implementation 'ru.github.igla:ferriswheel:1.1.1'
implementation 'com.github.Yalantis:Context-Menu.Android:1.0.8'
// implementation 'com.android.support:cardview-v7:23.+'
implementation 'com.jaredrummler:material-spinner:1.2.5'
implementation 'com.github.clans:fab:1.6.4'
implementation 'com.chauthai.swipereveallayout:swipe-reveal-layout:1.4.1'
implementation 'com.mapzen.android:speakerbox:1.4.1'
implementation 'com.github.adrielcafe:AndroidAudioConverter:0.0.8'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core:1.1.0'
implementation group: 'com.google.cloud', name: 'google-cloud-speech', version: '1.22.0'
}
I am getting this error when I try to build my project:
Duplicate class com.google.common.annotations.Beta found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.annotations.GwtCompatible found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.annotations.GwtIncompatible found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.annotations.VisibleForTesting found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.Absent found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.AbstractIterator found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.AbstractIterator$1 found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.AbstractIterator$State found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.Ascii found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.CaseFormat found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.CaseFormat$1 found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.CaseFormat$2 found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.CaseFormat$3 found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.CaseFormat$4 found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.CaseFormat$5 found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.CaseFormat$StringConverter found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.CharMatcher found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.CharMatcher$1 found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.CharMatcher$And found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.CharMatcher$BitSetMatcher found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.CharMatcher$FastMatcher found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.CharMatcher$NegatedFastMatcher found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.CharMatcher$Or found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.CharMatcher$RangesMatcher found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.Charsets found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.Converter found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.Converter$1 found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.Converter$1$1 found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.Converter$ConverterComposition found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.Converter$FunctionBasedConverter found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
Duplicate class com.google.common.base.Converter$IdentityConverter found in modules guava-28.1-android.jar (com.google.guava:guava:28.1-android) and guava-jdk5-17.0.jar (com.google.guava:guava-jdk5:17.0)
How to fix this?
After many hours of research I found the solution. The problematic dependency was this:
'com.google.apis:google-api-services-youtube:v3-rev204-1.23.0'
I solved it by using:
implementation ('com.google.apis:google-api-services-youtube:v3-rev204-1.23.0'){
exclude group:'com.google.guava'
}
If you face a similar issue, try to create a new Android project and import only the dependencies from your previous project. Then divide and conquer until you find the problematic dependency.
On the surface, do you need both com.google.guava:guava-jdk5:17.0 and com.google.guava:guava:28.1-android dependencies?
I've often seen those duplicate class errors arise in two scenarios:
1) Two libraries are using different versions of the same dependency.
2) Using androidx and support library together in a project. Your two guava dependencies may be using google commons classes that are present in androidx and support library.
You should verify that all support library dependencies are replaced with androidx and if that is done, consider excluding the conflicting classes packages from either com.google.guava:guava-jdk5:17.0 or com.google.guava:guava:28.1-android.
may be it's too late. However, I am writing an answer to your problem.
I had the same issue. I was using the Youtube Data API v3. After few searches and seeing answers from Stackoverflow, I mixed all of them and somehow it worked!!
Here is all I did and it worked.
Added configurations to app level build.gradle file. Like below
configurations {
implementation.exclude module:'gauva-jdk5'
all*.exclude group: 'com.google.guava', module: 'listenablefuture' }
Added these two lines in dependency block
implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava' implementation 'com.google.guava:guava:26.0-android'
And inside the dependencies needed for youtbe data api I hadded
exclude group:'com.google.guava'
Just like below
implementation ('com.google.api-client:google-api-client-android:1.22.0') {
exclude group: 'org.apache.httpcomponents'
exclude group:'com.google.guava'
}
implementation ('com.google.apis:google-api-services-youtube:v3-rev183-1.22.0') {
exclude group: 'org.apache.httpcomponents'
exclude group:'com.google.guava'
}
to more check out https://stackguides.com/questions/61480581/duplicate-class-found-in-modules-guava-26-0-android-jar-and-guava-jdk5-17-0-jar#
I was getting same error
"Duplicate class com.google.common.annotations.Beta found in modules jetified-guava-27.1-android (com.google.guava:guava:27.1-android) and jetified-guava-jdk5-17.0 (com.google.guava:guava-jdk5:17.0)"
I implemented Youtube in my app using YouTube data api v3, while adding this app as a module in my, main app I got same error.
I resolved this error by removing some dependency
implementation('com.google.api-client:google-api-client-android:1.23.0') {
exclude group: 'org.apache.httpcomponents'
}
implementation('com.google.apis:google-api-services-youtube:v3-rev183-1.22.0') {
exclude group: 'org.apache.httpcomponents'
}
implementation('com.google.api-client:google-api-client-android:1.23.0') {
exclude group: 'org.apache.httpcomponents'
}
Above all three library I added but this was useless and throwing errors so removed these all.

How to overcome Duplicate class issue while using Google Places SDK

I am converting my android app from older version of places SDK to the newer one as the older one is being decommissioned from July 29th. I made the changes as suggested by the documentation.
While compiling , I see loads of duplicate class error messages from classes that I don't use it evidently from my own code. Though they could used in libraries.
Duplicate class com.bumptech.glide.GeneratedAppGlideModule found in modules classes.jar (com.github.bumptech.glide:glide:4.3.1) and glide-4.3.1.jar (com.github.bumptech.glide:glide:4.3.1)
Duplicate class com.bumptech.glide.GenericTransitionOptions found in modules classes.jar (com.github.bumptech.glide:glide:4.3.1) and glide-4.3.1.jar (com.github.bumptech.glide:glide:4.3.1)
Duplicate class com.bumptech.glide.Glide found in modules classes.jar (com.github.bumptech.glide:glide:4.3.1) and glide-4.3.1.jar (com.github.bumptech.glide:glide:4.3.1)
Duplicate class com.bumptech.glide.GlideBuilder found in modules classes.jar (com.github.bumptech.glide:glide:4.3.1) and glide-4.3.1.jar (com.github.bumptech.glide:glide:4.3.1)
Duplicate class com.bumptech.glide.GlideBuilder$1 found in modules classes.jar (com.github.bumptech.glide:glide:4.3.1) and glide-4.3.1.jar (com.github.bumptech.glide:glide:4.3.1)
Duplicate class com.bumptech.glide.GlideContext found in modules classes.jar (com.github.bumptech.glide:glide:4.3.1) and glide-4.3.1.jar (com.github.bumptech.glide:glide:4.3.1)
Duplicate class com.bumptech.glide.ListPreloader found in modules classes.jar (com.github.bumptech.glide:glide:4.3.1) and glide-4.3.1.jar (com.github.bumptech.glide:glide:4.3.1)
Duplicate class com.bumptech.glide.ListPreloader$PreloadModelProvider found in modules classes.jar (com.github.bumptech.glide:glide:4.3.1) and glide-4.3.1.jar (com.github.bumptech.glide:glide:4.3.1)
Duplicate class com.bumptech.glide.ListPreloader$PreloadSizeProvider found in modules classes.jar (com.github.bumptech.glide:glide:4.3.1) and glide-4.3.1.jar (com.github.bumptech.glide:glide:4.3.1)
Duplicate class com.bumptech.glide.ListPreloader$PreloadTarget found in modules classes.jar (com.github.bumptech.glide:glide:4.3.1) and glide-4.3.1.jar (com.github.bumptech.glide:glide:4.3.1)
Duplicate class com.bumptech.glide.ListPreloader$PreloadTargetQueue found in modules classes.jar (com.github.bumptech.glide:glide:4.3.1) and glide-4.3.1.jar (com.github.bumptech.glide:glide:4.3.1)
Duplicate class com.bumptech.glide.MemoryCategory found in modules classes.jar (com.github.bumptech.glide:glide:4.3.1) and glide-4.3.1.jar (com.github.bumptech.glide:glide:4.3.1)
Duplicate class com.bumptech.glide.Priority found in modules classes.jar (com.github.bumptech.glide:glide:4.3.1) and glide-4.3.1.jar (com.github.bumptech.glide:glide:4.3.1)
Duplicate class com.bumptech.glide.Registry found in modules classes.jar (com.github.bumptech.glide:glide:4.3.1) and glide-4.3.1.jar (com.github.bumptech.glide:glide:4.3.1)
Duplicate class com.bumptech.glide.Registry$MissingComponentException found in modules classes.jar (com.github.bumptech.glide:glide:4.3.1) and glide-4.3.1.jar (com.github.bumptech.glide:glide:4.3.1)
Duplicate class com.bumptech.glide.Registry$NoImageHeaderParserException found in modules classes.jar (com.github.bumptech.glide:glide:4.3.1) and glide-4.3.1.jar (com.github.bumptech.glide:glide:4.3.1)
Duplicate class com.bumptech.glide.Registry$NoModelLoaderAvailableException found in modules classes.jar (com.github.bumptech.glide:glide:4.3.1) and glide-4.3.1.jar (com.github.bumptech.glide:glide:4.3.1)
Duplicate class com.bumptech.glide.Registry$NoResultEncoderAvailableException found in modules classes.jar (com.github.bumptech.glide:glide:4.3.1) and glide-4.3.1.jar (com.github.bumptech.glide:glide:4.3.1)
Duplicate class com.bumptech.glide.Registry$NoSourceEncoderAvailableException found in modules classes.jar (com.github.bumptech.glide:glide:4.3.1) and glide-4.3.1.jar (com.github.bumptech.glide:glide:4.3.1)
Duplicate class com.bumptech.glide.RequestBuilder found in modules classes.jar (com.github.bumptech.glide:glide:4.3.1) and glide-4.3.1.jar (com.github.bumptech.glide:glide:4.3.1)
Duplicate class com.bumptech.glide.RequestBuilder$1 found in modules classes.jar (com.github.bumptech.glide:glide:4.3.1) and glide-4.3.1.jar (com.github.bumptech.glide:glide:4.3.1)
Duplicate class com.bumptech.glide.RequestBuilder$2 found in modules classes.jar (com.github.bumptech.glide:glide:4.3.1) and glide-4.3.1.jar (com.github.bumptech.glide:glide:4.3.1)
Duplicate class com.bumptech.glide.RequestManager found in modules classes.jar (com.github.bumptech.glide:glide:4.3.1) and glide-4.3.1.jar (com.github.bumptech.glide:glide:4.3.1)
I came up across the repo's issues page but see no worthwhile updates
https://github.com/bumptech/glide/issues/3527
here goes my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.xxxxx.xxxxxx"
minSdkVersion 16
targetSdkVersion 26
versionCode 28
versionName '3.7'
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
lintOptions {
disable 'MissingTranslation'
checkReleaseBuilds false
abortOnError false
}
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
pickFirst 'META-INF/LICENSE.txt' // picks the JavaMail license file
}
productFlavors {
}
}buildscript {
repositories {
maven {
url "https://maven.java.net/content/groups/public/"
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.ramotion.foldingcell:folding-cell:1.2.2'
implementation 'com.sun.mail:android-mail:1.5.5'
implementation 'com.sun.mail:android-activation:1.5.5'
//implementation 'com.google.android.gms:play-services-places:15.0.1'
implementation 'com.google.android.gms:play-services-location:15.0.1'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.wdullaer:materialdatetimepicker:3.5.1'
implementation 'com.applandeo:material-calendar-view:1.4.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'gun0912.ted:tedpermission:2.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.google.firebase:firebase-crash:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.3.2'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.github.chrisbanes:PhotoView:2.1.0'
implementation 'commons-lang:commons-lang:2.6'
implementation 'org.jsoup:jsoup:1.10.1'
implementation 'com.google.android.libraries.places:places:1.1.0'
}
apply plugin: 'com.google.gms.google-services'
I tried to exclude the classes for compilation using gradle but I seem to be doing something wrong here (Quite new to Gradle though).
configurations {
compile.exclude group: 'com.bumptech.glide' , module: 'glide'
}
Is this snippet fine to exclude those classes being compiled ? and could I just add them in app's build.gradle?
Thank you so much for your inputs. Much appreciated

Categories

Resources