Execution failed for task ':app:checkDebugDuplicateClasses'. on Android studio 4.2.2

Viewed 2481

I'm using Android Studio 4.2.2 and my Gradle version is 6.7.1-bin
when running the project with the current configuration

build.gradle Module

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdkVersion 31
    buildToolsVersion "31.0.0"

    defaultConfig {
        applicationId "com.medicus.myapplication"
        minSdkVersion 21
        targetSdkVersion 31
        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.6.0'
    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

build.gradle project:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.5.21"
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.2.2"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter() // Warning: this repository is going to shut down soon
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

when running the project I get this error

Execution failed for task ':app:checkDebugDuplicateClasses'.

Could not resolve all files for configuration ':app:debugRuntimeClasspath'. Could not find constraintlayout-2.0.4.jar (androidx.constraintlayout:constraintlayout:2.0.4). Searched in the following locations: https://dl.google.com/dl/android/maven2/androidx/constraintlayout/constraintlayout/2.0.4/constraintlayout-2.0.4.jar Could not find viewpager2-1.0.0.jar (androidx.viewpager2:viewpager2:1.0.0). Searched in the following locations: https://dl.google.com/dl/android/maven2/androidx/viewpager2/viewpager2/1.0.0/viewpager2-1.0.0.jar Could not find drawerlayout-1.0.0.jar (androidx.drawerlayout:drawerlayout:1.0.0). Searched in the following locations: https://dl.google.com/dl/android/maven2/androidx/drawerlayout/drawerlayout/1.0.0/drawerlayout-1.0.0.jar Could not find coordinatorlayout-1.1.0.jar (androidx.coordinatorlayout:coordinatorlayout:1.1.0). Searched in the following locations: https://dl.google.com/dl/android/maven2/androidx/coordinatorlayout/coordinatorlayout/1.1.0/coordinatorlayout-1.1.0.jar Could not find dynamicanimation-1.0.0.jar (androidx.dynamicanimation:dynamicanimation:1.0.0). Searched in the following locations: https://dl.google.com/dl/android/maven2/androidx/dynamicanimation/dynamicanimation/1.0.0/dynamicanimation-1.0.0.jar Could not find transition-1.2.0.jar (androidx.transition:transition:1.2.0). Searched in the following locations: https://dl.google.com/dl/android/maven2/androidx/transition/transition/1.2.0/transition-1.2.0.jar Could not find vectordrawable-animated-1.1.0.jar (androidx.vectordrawable:vectordrawable-animated:1.1.0). Searched in the following locations: https://dl.google.com/dl/android/maven2/androidx/vectordrawable/vectordrawable-animated/1.1.0/vectordrawable-animated-1.1.0.jar Could not find vectordrawable-1.1.0.jar (androidx.vectordrawable:vectordrawable:1.1.0). Searched in the following locations: https://dl.google.com/dl/android/maven2/androidx/vectordrawable/vectordrawable/1.1.0/vectordrawable-1.1.0.jar Could not find recyclerview-1.1.0.jar (androidx.recyclerview:recyclerview:1.1.0). Searched in the following locations: https://dl.google.com/dl/android/maven2/androidx/recyclerview/recyclerview/1.1.0/recyclerview-1.1.0.jar Could not find cursoradapter-1.0.0.jar (androidx.cursoradapter:cursoradapter:1.0.0). Searched in the following locations: https://dl.google.com/dl/android/maven2/androidx/cursoradapter/cursoradapter/1.0.0/cursoradapter-1.0.0.jar Could not find cardview-1.0.0.jar (androidx.cardview:cardview:1.0.0). Searched in the following locations: https://dl.google.com/dl/android/maven2/androidx/cardview/cardview/1.0.0/cardview-1.0.0.jar

what should I do to fix this problem?

1 Answers

Open the gradle-wrapper.properties
and replace the version of the gradle with this versin

distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip

then sync the project. Then run the project.
The reason of this issue look that all gradle distributions with 6.* version has that issues with android studio 4.2.2 so using the latest version of gradle fixed the issues

Related