Home > Back-end >  Duplicate class in build.gradle file
Duplicate class in build.gradle file

Time:09-23

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.

CodePudding user response:

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

CodePudding user response:

You have duplicated your dependencies. Entries:

testImplementation 'junit:junit:4. '
testImplementation 'junit:junit:4.12'

Are pointing to the same library

  • Related