I'm in the process of adding a navigation drawer to my app. and I'm getting errors. The app gradle synchs just fine. but when I run the app I get a bunch of duplicate class error. I think it might be because I have conflicting dependencies added and that I'm using v7 28.0.0 and some of the errors mention app: v4. all the examples I've seen online use v7 28.0.0 eventhough I have this in main_activity.xml which uses v4. don't know if it's got something to do with the error. android.support.v4.widget.DrawerLayout
Caused by: com.android.ide.common.workers.WorkerExecutorException: 1 exception was raised by workers:
java.lang.RuntimeException: 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:24.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle$Delegate found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle$DelegateProvider found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle$SlideDrawable found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActivityCompat found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActivityCompat$1 found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.app.ActivityCompat$OnRequestPermissionsResultCallback found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "org.pctechtips.netdroid"
minSdkVersion 21
targetSdkVersion 28
versionCode 8
versionName "1.7"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled = false
signingConfig signingConfigs.config
}
buildTypes {
release {
shrinkResources false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable false
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
/*androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
firebase
implementation 'com.google.firebase:firebase-core:10.2.1'
})*/
// compile 'com.android.support:appcompat-v7:25.3.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
/*google play plugin for adMob*/
implementation 'com.google.android.gms:play-services:10.2.1'
implementation 'commons-net:commons-net:3.6'
implementation 'org.samba.jcifs:jcifs:1.3.3'
}
The exception means, There were duplicated classes in 2 or more different dependencies and the compiler wouldn't be able to distinguish which of them should be used at run-time and the exception was thrown.
Most often, Duplicity happens when you are trying to import modules that carrying their required libraries. (transitive dependencies)
You have to exclude duplicated classes from libraries in the build.gradle.
As Log shows, support-core-ui and support-compat modules have duplicated classes.
apply plugin: 'com.android.application'
android {
...
defaultConfig {
...
}
buildTypes {
...
}
configurations {
all { // You should exclude one of them not both of them
exclude group: "com.android.support", module: "support-core-ui"
exclude group: "com.android.support", module: "support-compat"
}
}
}
Sometimes you don't need to exclude anything and you only need to change the imported module to that one that does not bring its dependencies.
Other situation that causes duplicated classes is when you have added *.jar to the project libs directory. Therefore, You need to delete them if they are not begin used in the project.
project->app->libs->*.jar
I see there are some solutions mentioned using these 2 lines will resolve the problem But if you've migrated to Androidx it would be enabled by default.
android.useAndroidX=true
android.enableJetifier=true
Jetifier is
Jetifier tool migrates support-library-dependent libraries to rely on
the equivalent AndroidX packages instead. The tool lets you migrate an
individual library directly, instead of using the Android gradle
plugin bundled with Android Studio.
And for more information take a look at Exclude transitive dependencies
As an app grows in scope, it can contain a number of dependencies
including direct dependencies and transitive dependencies (libraries
which your app's imported libraries depend on). To exclude transitive
dependencies that you no longer need, you can use the exclude
keyword
If you have problems excluding classes, check this thread: How do I exclude...
See if adding this dependency works:
implementation 'com.android.support:support-v4:28.0.0'
Go to gradle.properties and write these two lines of code:
android.useAndroidX=true
android.enableJetifier=true
Please update com.google.android.gms:play-services to latest version. it wil work.
I tried all above solution, but nothing worked in my case. What worked for me is.
I got this problem resolved by creating a new project with the same project and package name and then copying files from the previous project to new one.
Related
I am trying to build an app with openCV and Firebase ML Kit. But I get the following error while building project:
Duplicate class com.google.android.gms.internal.vision.zze found in modules jetified-play-services-vision-20.0.0-runtime.jar (com.google.android.gms:play-services-vision:20.0.0) and jetified-play-services-vision-common-19.1.0-runtime.jar (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.jar (com.google.android.gms:play-services-vision:20.0.0) and jetified-play-services-vision-common-19.1.0-runtime.jar (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.jar (com.google.android.gms:play-services-vision:20.0.0) and jetified-play-services-vision-common-19.1.0-runtime.jar (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.jar (com.google.android.gms:play-services-vision:20.0.0) and jetified-play-services-vision-common-19.1.0-runtime.jar (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.jar (com.google.android.gms:play-services-vision:20.0.0) and jetified-play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)
Duplicate class com.google.android.gms.internal.vision.zzv found in modules jetified-play-services-vision-20.0.0-runtime.jar (com.google.android.gms:play-services-vision:20.0.0) and jetified-play-services-vision-common-19.1.0-runtime.jar (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.jar (com.google.android.gms:play-services-vision:20.0.0) and jetified-play-services-vision-common-19.1.0-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.0)
Go to the documentation to learn how to Fix dependency resolution errors.
I have tried searching exact same error and didn't get anything, then I searched duplicate class issues, there wasn't a certain way of solving the problem, everyone shared their experience and neither of them worked for me.
This is my build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.example.cameraactivity"
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'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'com.google.firebase:firebase-ml-vision:24.1.0'
implementation project(path: ':sdk')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
It's all about this line:
implementation 'com.google.firebase:firebase-ml-vision:24.1.0'
When I comment this line, it doesn't give errors when I build project (I haven't added functionality yet).
Thanks in advance
Add the following in build.gradle:Module
implementation 'com.google.android.gms:play-services-vision:20.0.0'
implementation 'com.google.firebase:firebase-ml-vision:24.0.3'
implementation 'com.google.firebase:firebase-ml-vision-barcode-model:16.1.1'
And in build.gradle:Project
classpath 'com.google.gms:google-services:4.3.3'
In buildscript-->dependencies.
I had the same issue with the 24.1.0 version of firebase-ml-vision.
Here is the official resolution solution :
Firebase Release Note MLKIT Self Serve Fixes
So I had to add a dependency to play-services-vision that I did not need anymore before :
implementation 'com.google.android.gms:play-services-vision:20.1.1'
I hope that they will fix it in the next versions
Alternatively and preferably, you should move to the new ML Kit SDK which we launched early June. The on-device APIs are considered deprecated in Firebase ML and updates / improvements are only available in the new SDK. To help with the switch, migration guides can be found here.
I have same issue,if you are using firebase dependencies update following to latest version in app/build.gradle see attached process
dependencies {
implementation platform('com.google.firebase:firebase-bom:29.0.0')
}
Get the latest version via the documentation
https://firebase.google.com/support/release-notes/android
We were facing a similar issue. I am going to add some steps here based on which hopefully someone else who faces this issue can later sort it out themselves.
Our issue was,
Execution failed for task ':app:checkStagingReleaseDuplicateClasses'.
> 1 exception was raised by workers: java.lang.RuntimeException: Duplicate class com.google.android.gms.internal.vision.zzbl found in modules play-services-vision-common-19.1.3-runtime.jar (com.google.android.gms:play-services-vision-common:19.1.3) and play-services-vision-face-contour-internal-16.0.0-runtime.jar (com.google.android.gms:play-services-vision-face-contour-internal:16.0.0)
We tried a lot of things, including steps mentioned here in these set of answers, but nothing worked. After a lot of brute forcing, and mind bending decryption of errors, we did this.
The error was simple, something was showing up in 2 places. Both places were not implemented anywhere in our build.gradle. So it was obviously coming from the group in which the module is placed, in our case com.google.android.gms. So, first we checked what's the version we have implemented for gms, only to realise nothing wrong there. Though we did play around a bit by upgrading and downgrading it, nothing really happened.
So we thought, why not just check where else in the app are one of the duplicates being implemented, only to realise, we have installed react-native-camera, which uses play-services-vision and has it implemented in it's own build.gradle. So now, a bulb went off in our head, we have implemented react-native-camera in our own build.gradle too. Like so
implementation project(':react-native-camera'). Why not make it stop trying to implement play-services-vision-face-contour-internal from our end?
Thus coming to the solution like so,
implementation (project(':react-native-camera')) {
exclude module: 'play-services-vision-face-contour-internal'
}
By doing this, the duplicate error stopped showing and we could continue with our development in peace.
I know there's not a lot of technical knowledge here, this is here just so someone could also look into something like this when they face something like this. I don't know if that made sense
I want to import Coil library in my project. I did it like below:
android{
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
implementation("io.coil-kt:coil:0.8.0")
}
The project will sync successfully, But When I want to run the application I 'll face with this error:
Duplicate class androidx.appcompat.content.res.AppCompatResources found in modules classes.jar (androidx.appcompat:appcompat-resources:1.1.0) and classes.jar (androidx.appcompat:appcompat:1.0.0)
Duplicate class androidx.appcompat.content.res.AppCompatResources$ColorStateListCacheEntry found in modules classes.jar (androidx.appcompat:appcompat-resources:1.1.0) and classes.jar (androidx.appcompat:appcompat:1.0.0)
Duplicate class androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat found in modules classes.jar (androidx.appcompat:appcompat-resources:1.1.0) and classes.jar (androidx.appcompat:appcompat:1.0.0)
Duplicate class androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat$1 found in modules classes.jar (androidx.appcompat:appcompat-resources:1.1.0) and classes.jar (androidx.appcompat:appcompat:1.0.0)
My app is converted to the AndroidX before. Also, my targetSdkVersion = 29 and minSdkVersion = 17
You need appcompat library
implementation "androidx.appcompat:appcompat:1.1.0"
You need appcompat library
implementation "androidx.appcompat:appcompat:1.1.0"
This is correct but you also need to
Go to gradle.properties and add
android.enableJetifier=true
android.useAndroidX=true
I had the same problem and I think it's related to the last version of Androidx.
Anyway you probably have one dependency using an old version of androidx.appcompat. Setting enableJetifier=true will force the use of the most recent one.
For info I'm using Coil on version
implementation "io.coil-kt:coil:0.10.0"
My android gradle build has many flavours.
One of then has an aar file that contains a duplicate dependency (com.google.zxing).
build.gradle:
...
dependencies {
implementation 'com.google.zxing:core:3.3.3'
implementation 'me.dm7.barcodescanner:zxing:1.9.8'
// Standard flavour
standardImplementation(name: 'libgedi-0.190121.gpos800', ext: 'aar') {
exclude group: 'com.google.zxing', module: 'android-core'
transitive = false
}
...
}
This configuration produces the following for "standard" build (works for another flavours):
Duplicate class com.google.zxing.BarcodeFormat found in modules core-3.3.3.jar (com.google.zxing:core:3.3.3) and zxing-2.1.jar (:libgedi-0.190121.gpos800:)
Duplicate class com.google.zxing.Binarizer found in modules core-3.3.3.jar (com.google.zxing:core:3.3.3) and zxing-2.1.jar (:libgedi-0.190121.gpos800:)
Duplicate class com.google.zxing.BinaryBitmap found in modules core-3.3.3.jar (com.google.zxing:core:3.3.3) and zxing-2.1.jar (:libgedi-0.190121.gpos800:)
Duplicate class com.google.zxing.ChecksumException found in modules core-3.3.3.jar (com.google.zxing:core:3.3.3) and zxing-2.1.jar (:libgedi-0.190121.gpos8
...
I tried to change the config to:
standardImplementation(name: 'libgedi-0.190121.gpos800', ext: 'aar') {
configurations {
all*.exclude group: 'com.google.zxing'
}
}
The config above works only when i'm build the "standard" flavour. To another flavors, this error occurs:
error: package com.google.zxing.qrcode.decoder does not exist
What i'm doing wrong?
Solution:
{
configurations {
exclude group: 'com.google.zxing'
}
}
use exclude instead all*exclude
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 Fix dependency resolution errors.
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 Fix dependency resolution errors.
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.
this solve for me
add below code in Android/app/build.gradle file
configurations {
compile.exclude group: 'com.google.zxing'
}
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
}
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.
Thanks to your comments I solved the issue like below image
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"
}
}
I have created a simple image to text app using Visual Studio following uTube guide https://www.youtube.com/watch?v=CLjzLiU_GpE
I am new to app dev and wanted to learn this but cant get to compile.
I have tried to follow similar errors in here
Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes?
When I try to follow this and add to the AndroidStudioProjects\ImageToTextApp\gradle.properties
I get more errors
My errors are as show but i have included (only) first and last 2, there are 390 in total.
I think i can see it tells me (as per other issues in here) that the class is in 2 libraries.
(com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Were do i see my project importing these libraries and how do I fix these errors.
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:24.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
...
Duplicate class android.support.v4.widget.ViewDragHelper$2 found in modules classes.jar (com.android.support:customview:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Duplicate class android.support.v4.widget.ViewDragHelper$Callback found in modules classes.jar (com.android.support:customview:28.0.0) and classes.jar (com.android.support:support-v4:24.0.0)
Go to the documentation to learn how to Fix dependency resolution errors.
Hi #BachVu
I added your suggested line and the build.gradle file now looks like
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0' implementation
'com.android.support.constraint:constraint-layout:2.0.0-beta1'
testImplementation 'junit:junit:4.13-beta-3'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.android.gms:play-services-vision:10.2.4'
exclude module: 'support-v4' }
But this just creates more errors
ERROR: Gradle DSL method not found: 'exclude()'
Do i need to add another import or have i added in the wrong place?
Try adding this line to the library that causes this issue exclude module: 'support-v4' like this:
implementation("androidx.recyclerview:recyclerview:x.x") {
exclude group: 'com.android.support'
exclude module: 'appcompat-v7'
exclude module: 'support-v4'
}
Here is my build.Gradle file now and all works fine;
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.0-beta1'
testImplementation 'junit:junit:4.13-beta-3'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.android.gms:play-services-vision:17.0.2' }
The main difference is
com.google.android.gms:play-services-vision:10.2.4
For some reason this was okay then out of nowhere it advised it was out of date. Once I updated from 10.2.4 > 17.0.2 all the errors went away.
Thanks for your time.
Try to migrate AndroidX
==> Step 1
Just go to
Refactor > Migrate to AndroidX > Migrate > Do Refactor
==> Step 2
Update your classPath and all dependencies with the latest version(Alt+Enter)
Go to gradle.properties and write these two lines of code:
android.useAndroidX=true # may be set already
android.enableJetifier=true