Closed harmit001 closed 2 years ago
any solution, I am facing the same issue ?
This may be caused by the specification changed of OkHttpClient
.
If it is used okhttp ver. 3.14.9, the body
is available as a method.
implementation 'com.squareup.okhttp3:okhttp:3.14.9
in build.gradle
.
val client = OkHttpClient()
val request = Request.Builder().url("ANY URL").build()
val response = client.newCall(request).execute()
val newString = response.body?.string() // Cannot access 'body': it is package-private in 'Response'
val oldString = response.body()?.string() // work fine
If that of ver. 4.0.0 or later, the body
is available as a property.
implementation 'com.squareup.okhttp3:okhttp:4.0.0
in build.gradle
.
val newString = response.body?.string() // work fine'
val oldString = response.body()?.string() // Using 'body(): ResponseBody()' is an error. moved to val
If you need to use okhttp libraries below version 4 due to consistency with other libraries, you could change the above section to a method.
Error in Android: cannot access 'body': it is package-private in 'response'