Why is my JSONObject related unit test failing?

前端 未结 3 507
天涯浪人
天涯浪人 2020-12-08 18:34

I\'m running my tests using gradle testFlavorType

JSONObject jsonObject1 = new JSONObject();
JSONObject jsonObject2 = new JSONObject();
jsonObje         


        
3条回答
  •  一整个雨季
    2020-12-08 19:14

    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 {
        ...
        testCompile 'org.json:json:20200518'
    }
    

    You can replace the version 20200518 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 {
        ...
        testCompile 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

提交回复
热议问题