개발/Android Studio 에러

에러: Duplicate class error org.hamcrest.BaseDescription found in modules

스몰스테핑 2024. 5. 23. 17:44

Duplicate Class 에러는 동일한 클래스가 두 번 이상 정의되었을 때 발생한다.

 

Duplicate class org.hamcrest.core.IsSame found in modules hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.internal.ArrayIterator found in modules hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.internal.SelfDescribingValue found in modules hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.internal.SelfDescribingValueIterator found in modules hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10 (junit:junit:4.10)

Go to the documentation to learn how to Fix dependency resolution errors.

 

https://stackoverflow.com/questions/59085448/duplicate-class-org-hamcrest-basedescription-found-in-modules-jetified-hamcrest

 

Duplicate class org.hamcrest.BaseDescription found in modules jetified-hamcrest-core-1.3.jar

Android studio 3.6 app/build.gradle: androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'com.azimolabs.conditionwatcher:conditionwatcher:0.2' // Espresso

stackoverflow.com

 

Build.gradle (Module: app)의 android {} 안에 다음과 같은 코드를 작성하라고 한다.

configurations.all {
    resolutionStrategy.dependencySubstitution {
        substitute module('org.hamcrest:hamcrest-core:1.1') with module('junit:junit:4.10')
    }
}

 

 

오래되서 그런지 오류가 뜬다...

다음과 같이 변경하면 된다.

configurations.all {
        resolutionStrategy.dependencySubstitution {
            substitute(module("org.hamcrest:hamcrest-core:1.1")).using(module("junit:junit:4.10"))
        }
    }