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

Clarify usage for proguard/R8 in README #488

Closed
MaxMello opened this issue Aug 26, 2021 · 2 comments · Fixed by #494
Closed

Clarify usage for proguard/R8 in README #488

MaxMello opened this issue Aug 26, 2021 · 2 comments · Fixed by #494
Assignees

Comments

@MaxMello
Copy link
Contributor

Use case
When using Jackson with Kotlin on Android, the README of this project suggests that at most the two stated proguard rules have to be added, and after that Jackson should just work with features like data classes etc. For me, this was not the case, and most solutions found on StackOverflow and other sources mention that they also use a keep rule for their Kotlin classes that shall be (de-)serialized, or else it won't work. And in fact, only after I added another keep rule did Jackson with Kotlin actually work when running on Android devices. The fact that this requirement was not listed on the official README led me to believe that is was explicitly not required.

Describe the solution you'd like
Add another bullet point to the README that mentions that the classes itself need to be kept with proguard, or else it won't/might not work.

Describe alternatives you've considered
An alternative would be that this is not expected behavior and that in fact it should work with only these two proguard rules. In that case, there might be other problems with how jackson-module-kotlin and R8/proguard interact. My error messages did in fact differ depending on the Android Gradle Plugin version (4.2 and 7) (which determines the proguard / R8 version), but were all either com.fasterxml.jackson.databind.exc.InvalidDefinitionException or java.lang.NoSuchMethodError. Those errors went away the moment I added the rule -keep class my.package.** { *; }.

Additional context
Here is a posts mentioning a rule they use to get jackson-module-kotlin and Proguard to work: https://medium.com/@AthorNZ/kotlin-metadata-jackson-and-proguard-f64f51e5ed32. The rule is -keepclassmembers public class com.mypackage.** { public synthetic <methods>; }. This rule did not work for me, but it might work for others, so a general info about the requirement to also add a keep rule for the classes to (de-)serialize (not just the Metadata annotation) should be appropriate, as it is unspecific enough to apply to different scenarios (versions of proguard/R8 etc.).

@dinomite
Copy link
Member

Could you suggest (or PR) some language for the readme that would have been helpful for you? I've never used ProGuard, so what I would come up with is likely to be confusing, at best.

@MaxMello
Copy link
Contributor Author

I've created a pull request #494. I can't really claim any certainty when this rule would be needed and when not, but maybe it can help others find out for their case.

@dinomite dinomite self-assigned this Aug 29, 2021
@dinomite dinomite linked a pull request Aug 29, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants