https://kotlinlang.org logo
Title
r

Rover Sanchez

01/27/2022, 11:23 AM
Hi guys, Has anybody else troubles trying to include the "io.ktor:ktor-client-okhttp:2.0.0-beta-1" dependency? It just could not resolve although I've included google an maven Central repository
a

Aleksei Tirman [JB]

01/27/2022, 11:56 AM
Please try to add
-jvm
suffix so it will look like
io.ktor:ktor-client-okhttp-jvm:2.0.0-beta-1
. Does it work after this change?
r

Rover Sanchez

01/27/2022, 11:59 AM
i´m afraid no. it´s still: Could not resolve io.ktor:ktor-client-okhttp-jvm:2.0.0-beta-1.
a

Aleksei Tirman [JB]

01/27/2022, 12:00 PM
That's strange. It works on my machine with and without that suffix.
m

MarkRS

01/27/2022, 12:00 PM
I can't even get it to resolve io.ktor:ktor-client-okhttp:1.6.7 Same thing? I don't know, but it's preventing my builds 😞
r

Rover Sanchez

01/27/2022, 12:00 PM
mmm
do you try to download right no?
or do you have it cached?
m

MarkRS

01/27/2022, 12:01 PM
Errr, pardon? It can't find it. Surely the build should find it if it's local?
r

Rover Sanchez

01/27/2022, 12:01 PM
other dependencies are working, like "io.ktor:ktor-client-android:2.0.0-beta-1"
but no this one
if you have cached the dependency, and you work offline, you should compile
but, for me, I can´t download it
m

MarkRS

01/27/2022, 12:14 PM
The problem survives a "clear caches", so it's a failure to download for me too.
a

Aleksei Tirman [JB]

01/27/2022, 12:15 PM
What error did you get from Gradle?
r

Rover Sanchez

01/27/2022, 12:15 PM
Could not resolve io.ktor:ktor-client-okhttp-jvm:2.0.0-beta-1.
a

Aleksei Tirman [JB]

01/27/2022, 12:16 PM
Usually, there are also more descriptive error messages.
r

Rover Sanchez

01/27/2022, 12:16 PM
it´s like the repository doesn´t provide the artifactory
a

Aleksei Tirman [JB]

01/27/2022, 12:17 PM
What if you click on the top entry?
r

Rover Sanchez

01/27/2022, 12:18 PM
nothing
even i´ve got Build Successful
but, in the code, I can´t import and use the classes
a

Aleksei Tirman [JB]

01/27/2022, 12:19 PM
So your project compiles fine?
And you can run it?
r

Rover Sanchez

01/27/2022, 12:19 PM
yes, it compile, and i can run, but I can´t use that dependency
a

Aleksei Tirman [JB]

01/27/2022, 12:19 PM
Please share your code snippet
r

Rover Sanchez

01/27/2022, 12:20 PM
which one?
a

Aleksei Tirman [JB]

01/27/2022, 12:20 PM
Where you try to use OkHttp
r

Rover Sanchez

01/27/2022, 12:20 PM
the gradle file?
m

MarkRS

01/27/2022, 12:20 PM
Here, the import has been marked as a failure for a long time, but it's just recent that it now won't build. I'm using OkHttp in a commonMain .kt file
a

Aleksei Tirman [JB]

01/27/2022, 12:20 PM
No, your application code
r

Rover Sanchez

01/27/2022, 12:22 PM
I´ve just copy the code from here:
import io.ktor.client.engine.okhttp.*
val client = HttpClient(OkHttp)
this is not working
if i included this code, I can´t compile
a

Aleksei Tirman [JB]

01/27/2022, 12:26 PM
@Rover Sanchez is your project multiplatform?
r

Rover Sanchez

01/27/2022, 12:27 PM
yes
I´ve included this dependency in the shared buuild.gradle
a

Aleksei Tirman [JB]

01/27/2022, 12:29 PM
For the jvmMain sourceset, right?
r

Rover Sanchez

01/27/2022, 12:30 PM
mm, no
a

Aleksei Tirman [JB]

01/27/2022, 12:30 PM
OkHttp engine is JVM only
🙄 1
:thank-you: 1
r

Rover Sanchez

01/27/2022, 12:30 PM
for the commonMain
ohh, fuck
that´s a good explanation
sorry man, that´s my fault
@Aleksei Tirman [JB], do you know if there is another way to include interceptors? for ios an android at least
a

Aleksei Tirman [JB]

01/27/2022, 12:35 PM
Yes, you can add interceptors for the Ktor client
r

Rover Sanchez

01/27/2022, 12:36 PM
do you have a link or some example?
I´ve seen that for OkHTTP
a

Aleksei Tirman [JB]

01/27/2022, 12:36 PM
There is not much information in the documentation about this topic. What do you need to implement?
r

Rover Sanchez

01/27/2022, 12:41 PM
it´s just a poc right now
i want to know hoy i should do it
I´ve seen how to add Authentication
but, I want to know if there is a way of do whatever
like we ususally do with okhttp
a

Aleksei Tirman [JB]

01/27/2022, 12:46 PM
For example, that's how you can add a custom header for every request:
val client = HttpClient()
client.requestPipeline.intercept(HttpRequestPipeline.Render) {
    context.header("custom", "123")
}
r

Rover Sanchez

01/27/2022, 12:48 PM
mm, nice
it´s good to know
a

Aleksei Tirman [JB]

01/27/2022, 12:49 PM
Also, there are
client.receivePipeline
and
client.sendPipeline
r

Rover Sanchez

01/27/2022, 12:49 PM
I think for now it´s enough
thanks a lot for your help @Aleksei Tirman [JB]