Okhttp: Get Request error

Created on 10 Feb 2019  路  2Comments  路  Source: square/okhttp

Hello, im trying to make a simple get request to retrieve a JSON using this library, with kotlin. However, i get this in the console:

AGPBI: {"kind":"error","text":"Static interface methods are only supported starting with Android N (--min-api 24): okhttp3.Request okhttp3.Authenticator.lambda$static$0(okhttp3.Route, okhttp3.Response)","sources":[{}],"tool":"D8"}
FAILURE: Build failed with an exception.

Failed to transform file 'okhttp-3.13.1.jar' to match attributes {artifactType=android-dex, dexing-is-debuggable=true, dexing-min-sdk=15} using transform DexingTransform
Error while dexing.

I m pretty new to android development(i am an iOS dev), so i may be missing something but the code im using comes from various tutorials, and i do not understand what could be the issue.

This is the code:

private val url = "..."
private val client = OkHttpClient()
private val request = Request.Builder().url(url).build()
fun fetchJson(){

        client.newCall(request).enqueue(object: Callback{
            override fun onFailure(call: Call, e: IOException) {
                println("Http request failed: ${e.localizedMessage}")
            }

            override fun onResponse(call: Call, response: Response) {
                val result = response.body().let {
                    it!!.string()
                }
                println("The response is: $result")
            }

        })
    }

I have used gradle to integrate it within my project. Pasting on google parts of the log above did not help at all, i did not found any useful solution.
Thank you for the attention.

bug

Most helpful comment

you apply this code in your Grande it will work
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

All 2 comments

See https://github.com/square/okhttp/issues/4597#issuecomment-461204144. You need to update your build configuration.

you apply this code in your Grande it will work
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

Was this page helpful?
0 / 5 - 0 ratings