With okhttp 5.1 my minified android build fails wi...
# squarelibraries
u
With okhttp 5.1 my minified android build fails with
Copy code
> Task :foo:app:minifyTstStableReleaseWithR8 FAILED
ERROR: Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /Users/bar/AndroidStudioProjects/foo/app/build/outputs/mapping/tstStableRelease/missing_rules.txt.
ERROR: R8: Missing class okhttp3.internal.Util (referenced from: void okhttp3.internal.sse.RealEventSource.processResponse(okhttp3.Response) and 1 other context)
Anyone else experiencing this?
c
what version of okhttp are you using? the last time i got this it was because i was out of date
u
5.1.0
c
can you also post contents of missing_rules.txt?
u
Copy code
# Please add these rules to your existing keep rules in order to suppress warnings.
# This is generated automatically by the Android Gradle plugin.
-dontwarn okhttp3.internal.Util
Copy code
Caused by: com.android.tools.r8.internal.g: Missing class okhttp3.internal.Util (referenced from: void okhttp3.internal.sse.RealEventSource.processResponse(okhttp3.Response) and 1 other context)
        at com.android.tools.r8.internal.gh0.a(R8_8.12.14_57c4cb949dc9299c08af76e64a45e2178c74cd3ffb240ebd6ec37814bb254d10:21)
        at com.android.tools.r8.internal.gh0.error(R8_8.12.14_57c4cb949dc9299c08af76e64a45e2178c74cd3ffb240ebd6ec37814bb254d10:1)
        at com.android.tools.r8.shaking.M.a(R8_8.12.14_57c4cb949dc9299c08af76e64a45e2178c74cd3ffb240ebd6ec37814bb254d10:6844)
        at com.android.tools.r8.shaking.M.a(R8_8.12.14_57c4cb949dc9299c08af76e64a45e2178c74cd3ffb240ebd6ec37814bb254d10:1683)
        at com.android.tools.r8.R8.a(R8_8.12.14_57c4cb949dc9299c08af76e64a45e2178c74cd3ffb240ebd6ec37814bb254d10:1628)
        at com.android.tools.r8.R8.a(R8_8.12.14_57c4cb949dc9299c08af76e64a45e2178c74cd3ffb240ebd6ec37814bb254d10:210)
        at com.android.tools.r8.R8.c(R8_8.12.14_57c4cb949dc9299c08af76e64a45e2178c74cd3ffb240ebd6ec37814bb254d10:11)
        at com.android.tools.r8.R8.a(R8_8.12.14_57c4cb949dc9299c08af76e64a45e2178c74cd3ffb240ebd6ec37814bb254d10:5)
        at com.android.tools.r8.internal.Gv.a(R8_8.12.14_57c4cb949dc9299c08af76e64a45e2178c74cd3ffb240ebd6ec37814bb254d10:28)
        ... 32 more
is what I see in console, bit more info
c
Hm. I'd maybe open up a bug in okhttp since you're running latest. In the meantime... you can just add
-dontwarn okhttp3.internal.Util
to your proguard config file
u
Tbh I'm never sure with the downwarn..what does that mean exactly, thats its missing on purpose?
c
Not sure but I had a similar issue many months ago, but then there was a bug about it on github, and then it was fixed in 4.11 https://github.com/square/okhttp/blob/master/docs/changelogs/changelog_4x.md#version-4110
y
I'd check you are using a consistent OkHttp version.
☝️ 1
There is a BOM you can apply that will keep everything on the same version, or at least should.
c
tangent: don't all okhttp group share the same version between all artifacts? why even need a bom?
y
They do.
👀 1
Gradle doesn't bump okhttp-brotli 4.11.0 if you bring in say okhttp 5.1.0
u
im directly only including these two
Copy code
okhttp-client = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
okhttp-loggingInterceptor = { module = "com.squareup.okhttp3:logging-interceptor", version.ref = "okhttp" }
y
And OkHttp doesn't have stable APIs between the modules. There is a lot of internal APIs that can change.
u
so should I look for transitive stuff?
y
Yep.
u
curious why is this an issue? gradle should overwrite all the versions with the highest (i.e. what I set)
okay now I see, sorry for rubber ducking so my only solution is to find that
okhttp-what-im-not-using-directly
, i.e. find the offending library that includes it and then include it myself with the 5.1.0, so the gradle overwriting kicks in, right?
y
I guess one of? 1. Apply the BOM? 2. Use a gradle dependency override (for the package group) 3. explicitly list anything that you transitively import with a newer version
u
thanks for the points, I think I see it now
btw about the BOMs, do you find them ergonomic (in a many module project)? while it would solve this issue .. I need to apply it everywhere, which is annoying .. turned my gradle single line to two lines
y
They seem like the least worst option for Gradle.
yes black 1
For Maven, they are essential because of it's bonkers version resolution rules (something like closest?)
OkHttp having a stable public API between modules would be a cleaner solution, but it's awkward because OkHttp tries to have a minimal public API, meaning a lot of things are internal across modules.
u
btw does it make sense to you that debug builds yet release doesnt?
y
I guess if R8 isn't running the same steps?
But may surface at runtime if you hit that codepath instead
u
For completeness I'll paste it here -- you were right
Copy code
+--- io.ktor:ktor-client-okhttp:3.2.3
|    |    |    |    |    \--- io.ktor:ktor-client-okhttp-jvm:3.2.3
|    |    |    |    |         +--- org.slf4j:slf4j-api:2.0.17
|    |    |    |    |         +--- io.ktor:ktor-client-core:3.2.3 (*)
|    |    |    |    |         +--- com.squareup.okhttp3:okhttp:4.12.0 -> 5.1.0 (*)
|    |    |    |    |         +--- com.squareup.okhttp3:okhttp-sse:4.12.0 <----------