Duplicate Hamcrest Class Errors When Runtime Dependsancy On Json-Simple Added
07:31 29 Dec 2025

I am using the latest stable version of Android Studio (Otter 2) and my library dependances are not reporting any newer versions available.

I am writing a class that will parse JSON objects with lives in a library module that will be used in both this Android app and in a Jakarta based server. Therefore I selected com.googlecode.json-simple:json-simple as the JSON parser library to use.

Adding this library produces a number dupl;icate class errors relating to the hamcrest-core-1.1.jar library (see below). Removing my library and adding a runtimeOnly depensancy on the json-simple library also produces the errors.

Google searching the issue I found a number of suggestions in the theme of:

configurations {
    compile.exclude group: "junit", module: "junit"
}

Dome where as old as 10 years afo. Either they did not fix the problem (whether I added the suggestion in the android block or at the top level), or they failed syntaxicly. So I am either missing something simple or they don't work for the version of Gradle I'm using (8.13).

As always, may thanks for any suggestions.

The duplicate errors:

Duplicate class org.hamcrest.BaseDescription found in modules hamcrest-core-1.1.jar -> hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar -> junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.BaseMatcher found in modules hamcrest-core-1.1.jar -> hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar -> junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.CoreMatchers found in modules hamcrest-core-1.1.jar -> hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar -> junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.Description found in modules hamcrest-core-1.1.jar -> hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar -> junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.Factory found in modules hamcrest-core-1.1.jar -> hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar -> junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.Matcher found in modules hamcrest-core-1.1.jar -> hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar -> junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.SelfDescribing found in modules hamcrest-core-1.1.jar -> hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar -> junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.StringDescription found in modules hamcrest-core-1.1.jar -> hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar -> junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.AllOf found in modules hamcrest-core-1.1.jar -> hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar -> junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.AnyOf found in modules hamcrest-core-1.1.jar -> hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar -> junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.DescribedAs found in modules hamcrest-core-1.1.jar -> hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar -> junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.Is found in modules hamcrest-core-1.1.jar -> hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar -> junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsAnything found in modules hamcrest-core-1.1.jar -> hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar -> junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsEqual found in modules hamcrest-core-1.1.jar -> hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar -> junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsInstanceOf found in modules hamcrest-core-1.1.jar -> hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar -> junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsNot found in modules hamcrest-core-1.1.jar -> hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar -> junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsNull found in modules hamcrest-core-1.1.jar -> hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar -> junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsSame found in modules hamcrest-core-1.1.jar -> hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar -> junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.internal.ArrayIterator found in modules hamcrest-core-1.1.jar -> hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar -> junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.internal.SelfDescribingValue found in modules hamcrest-core-1.1.jar -> hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar -> junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.internal.SelfDescribingValueIterator found in modules hamcrest-core-1.1.jar -> hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and junit-4.10.jar -> junit-4.10 (junit:junit:4.10)
android gradle hamcrest