10

I had 3 line code to get body from OkHttp3 source:

val responseBody = response.peekBody(response.body()!!.contentLength())
val source = GzipSource(responseBody.source())
val body = Okio.buffer(source).readUtf8() //issue is that line

on another computer I get error: "Using 'buffer(Source): BufferedSource' is an error. moved to extension function"

So fix it by replacing last line by:

val body = source.buffer().readUtf8()

bun now on the fist computer I have error: "Unresolved reference: buffer" so I need to revert that change.

What is wrong? base on error message I cannot figure out. It seems that it's issue with gradle configuration. But what? How to have compiling code on both computers.

LunaVulpo
  • 3,043
  • 5
  • 30
  • 58

2 Answers2

10

add implementation "com.squareup.okio:okio:2.3.0" to your build.gradle

MikeRzDev
  • 116
  • 1
  • 2
  • Do you have an explanation / reason why this happens? – David Medenjak Aug 30 '19 at 10:40
  • maybe one or more libraries on your project uses okio latest version but also one or more uses an older version. On its latest version okio enforces to use the new notation for various methods / kotlin extensions if you are using the old notation of those methods the library itself forces the compiler to throw a compilation error if detects that you are using some the old notation of a method. sorry if its a bit confusing :p – MikeRzDev Sep 03 '19 at 05:09
8

I had trouble figuring it out, so I will describe what I did to "fix it".

They changed Okio to work with kotlin extension, in this URL you can find the change log with all changes. https://square.github.io/okio/changelog/#version-200-rc1

In my case I was trying to make a unit test pass.

The old way was:

val inputStream = javaClass.classLoader.getResourceAsStream("api-response/$fileName")
val source = Okio.buffer(Okio.source(inputStream))

and the new way is:

val inputStream = javaClass.classLoader!!
.getResourceAsStream("api-response/$fileName")
.source()
.buffer()
Henrique Vasconcellos
  • 1,144
  • 1
  • 8
  • 13