Why is my JSONObject related unit test failing?

As Lucas says, JSON is bundled up with the Android SDK, so you are working with a stub.

The current solution is to pull JSON from Maven Central like this:

dependencies {
    ...
    testImplementation 'org.json:json:20210307'
}

You can replace the version 20210307 with the the latest one depending on the Android API. It is not known which version of the maven artefact corresponds exactly/most closely to what ships with Android.

Alternatively, you can download and include the jar:

dependencies {
    ...
    testImplementation files('libs/json.jar')
}

Note that you also need to use Android Studio 1.1 or higher and at least build tools version 22.0.0 or above for this to work.

Related issue: #179461

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)