fleeksoft / ksoup

Ksoup is a Kotlin Multiplatform library for working with HTML and XML. It's a port of the renowned Java library Jsoup.
https://fleeksoft.github.io/ksoup/
Apache License 2.0
315 stars 12 forks source link

R8 on Android with Ktor3 & Ksoup #95

Closed vanniktech closed 3 weeks ago

vanniktech commented 1 month ago

I've just tried to update my apps to the ksoup variant with ktor3 since ktor3 is now stable. When trying to build my Android app I've gotten the following:

ERROR: R8: Missing class io.ktor.utils.io.core.ByteReadPacket (referenced from: int com.fleeksoft.ksoup.io.CharsetImpl.decode(java.lang.StringBuilder, byte[], int, int))
Missing class io.ktor.utils.io.core.ByteReadPacketExtensionsKt (referenced from: int com.fleeksoft.ksoup.io.CharsetImpl.decode(java.lang.StringBuilder, byte[], int, int))
Missing class io.ktor.utils.io.core.Input (referenced from: int com.fleeksoft.ksoup.io.CharsetImpl.decode(java.lang.StringBuilder, byte[], int, int))

Does Ksoup require proguard rules with ktor3? This never happened with the ktor2 variant of ksoup.

itboy87 commented 1 month ago

@vanniktech I think somehow these references are from an older version of Ktor 2. Can you please make sure your project doesn’t have any Ktor 2 dependencies and that you are using ksoup dependencies without Ktor 2 for both ksoup and ksoup-network?

vanniktech commented 4 weeks ago

Nope. I'm all ktor3

itboy87 commented 4 weeks ago

I tried, but I can’t reproduce this issue. Could you provide minimal sample code to reproduce this issue?

vanniktech commented 4 weeks ago

Weird. I've tried again, but this time I did a gradle clean and now it works.

vanniktech commented 3 weeks ago

First of all, I mixed up my project. I use it in two of my apps. Same repository. I know what the problem is. It is ksoup itself.

Screenshot 2024-11-02 at 21 31 12

So the okio module that you have is using ktor2, but in my app I'm already using ktor3, therefore it is being upgraded and then it rightfully complains.

So to fix this, either the ksoup-okio needs to be free from ktor dependencies or there need to be 2 different modules, once for ktor2 and one for ktor3.

itboy87 commented 3 weeks ago

Yes, I have published one called ksoup-okio-ktor3, which you can use. However, in the upcoming version, I have already removed the Ktor dependency from the core, and in the future, it will consist of simpler and more extensible modules

vanniktech commented 3 weeks ago

Amazing, that worked!