Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Okhttp4, Cannot access 'body': it is package-private in 'Response'

i'm migrating from okhttp 3.14 to okhttp4, accordings to migration guide, when replacing "response.body()?" call to "response.body?" IDE shows error " Cannot access 'body': it is package-private in 'Response' " at last line of code

val request = Request.Builder().url(url).build()
        val response = coreNetwork.getOkHttp().newCall(request).execute()
        val stream = response.body?.source()?.inputStream()

if i'm trying "response.body()?" call, shows error " Using 'body(): ResponseBody?' is an error. moved to val " as expected.

like image 644
Andrei K Avatar asked Oct 17 '25 13:10

Andrei K


1 Answers

Solved, i'm start watching to what version of okhttp linked every import, and one interface linked to okhttp-3.12.0.jar. This interface belongs to separate gradle module, and i found that i forgot add a dependency ' implementation "com.squareup.okhttp3:okhttp:4.2.2" ' to .gradle file of that module. (in that case class should not found okhttp dependency at all, but somehow found old version and depends on it)

like image 189
Andrei K Avatar answered Oct 20 '25 04:10

Andrei K



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!