How to fix: "Unresolved reference: buffer" or "Using 'buffer(Source): BufferedSource' is an error. moved to extension function"?

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


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()

Tags:

Android

Okio