Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing Prougard rule #44

Open
eyedol opened this issue Apr 5, 2024 · 3 comments
Open

Missing Prougard rule #44

eyedol opened this issue Apr 5, 2024 · 3 comments

Comments

@eyedol
Copy link

eyedol commented Apr 5, 2024

Usage of the library causes app to crash with Android release builds because R8 removes unused classes or methods from the Ksoup library. Specifically, Builder#onOpenTag is stripped out, causing a crash when only Builder#onCloseTag is called in the app.

Here's a simplified example of how the library is used in the app:

val handler = KsoupHtmlHandler
  .Builder()
  .onOpenTag { name, attributes, _ -> Logger.d { "tag opening name: $name" } }
  .onCloseTag { name, _ -> Logger.d { "tag closing name: $name" } }
  .build()
  
val parser = KsoupHtmlParser(handler)
try {
  val html = "<p> Welcome to my home page. </p>"
  parser.write(html)
} finally {
  parser.end()
}  

Adding the following ProGuard rule resolves the issue:

-keep class com.mohamedrejeb.ksoup.html.parser.KsoupHtmlHandler.Builder**, * { *; }

Ideally, this rule could be shipped with the library to avoid manual configuration by consumers?

I'm unsure of the best way forward, but I believe this issue warrants further investigation.

P.S. Thanks for the library, saved me a ton of time parsing html tags in a KMM project

@MohamedRejeb
Copy link
Owner

Hi,
You are right, it's better to have the necessary ProGuard rules shipped with the library.
It will be available in the next release.

@eyedol
Copy link
Author

eyedol commented Apr 11, 2024

Thanks for confirming and considering it for inclusion in the next release.

@vanniktech
Copy link

Are we using reflection? If not, this should not be stripped and if so is a bug with R8. Adding that proguard rule does not seem right, since onOpenTag should be stripped out if no one is using it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants