Where can I find the recommended configuration for using Jackson with ProGuard?
@johnjohndoe Please use mailing lists for questions (https://groups.google.com/forum/#!forum/jackson-user).
I do not the answer, but if one is found I can add to FAQ.
I posted on the mailing list now. However, I am very much surprised the ProGuard settings are not part of the official documentation.
@johnjohndoe Thanks!
Official documentation, like everything, is based on contributions, so the lack is because no one has shared their definitions for documentation (I presume there are enough Android developers that need them so they exist). I don't develop on Android personally, for example, so I can't directly help here. So let's hope some community member is able and willing to help here.
Here is what I use since a while in production - be aware of the broad scope of these rules:
# Jackson
-keep @com.fasterxml.jackson.annotation.JsonIgnoreProperties class * { *; }
-keep class com.fasterxml.** { *; }
-keep class org.codehaus.** { *; }
-keepnames class com.fasterxml.jackson.** { *; }
-keepclassmembers public final enum com.fasterxml.jackson.annotation.JsonAutoDetect$Visibility {
public static final com.fasterxml.jackson.annotation.JsonAutoDetect$Visibility *;
}
# General
-keepattributes SourceFile,LineNumberTable,*Annotation*,EnclosingMethod,Signature,Exceptions,InnerClasses
@johnjohndoe thank you! I can add this with some verbiage on jackson-docs:
https://github.com/FasterXML/jackson-docs
although if you had time it would be great to get a section (either on main README, or as a wiki page) outlining other things about use on Android platform. But I think this should be valuable since as you pointed out this is needed by many and having baseline can save lots of time.
Added sample settings at: https://github.com/FasterXML/jackson-docs/wiki/JacksonOnAndroid
Thank you again!
This library is too heavy 444kB after proguarding? Not sure why. These rules don't help in reducing it either. Can someone helpout?
Do you maybe have -dontshrink in your config?
-keep class com.fasterxml.* { *; }
-keep class org.codehaus.* { *; }
!!
@johnjohndoe Those rules are extremely broad. We might as well not be using proguard :/
Are there any better proguard rules? @AdityaAnand1 nailed it... this is incredibly broad. why even use proguard then?
@thebehera This is not a discussion board (esp. closed issues...): for questions, discussion, please use mailing list:
https://groups.google.com/forum/#!forum/jackson-user
as to definitions, this is an OSS project so if you have something to contribute, please do so.
I gather many other Android developers would find them useful.
Commentary on goodness or lack thereof of others suggestion is counter-productive if you nothing positive to contribute.
Completely agree @cowtowncoder, however...
From personal experience, I have to set aside an entire day before pushing to production to just deal with proguard errors because so many libraries simply offer such broad rules instead of a real solution. So I have to manually dissect each warning and traverse the inner workings of every single library to figure out which ones I have to -keep and which ones I can -dontwarn.
Just my 2 cents 馃槃
@AdityaAnand1 Yes, I agree in that all-around feedback is useful. Maybe it's more about just formulating way to point out things in respectful way. I do not mean to say only positive comments serve purpose.
How about this: could you file another issue, requesting improved, more selective ProGuard definitions. And then, bring it up on the user mailing list? Thing is, I personally do not (alas!) have experience with ProGuard, as I do not develop on Android. I do have general idea to know what I do not know, and I am not aware of other active contributors with knowledge either. But it is rather possible someone might have background and just could use a nudge or reminder. As you said, it is a very important area, and I fully agree with that.
Thank you for the discussion here: this is how things improve in my opinion.
I came across this proguard config that resolved my issues (and seems to be a bit better on the shrinking front, as it only keeps the names aka doesnt obfuscate the classes/members but still removes unused code)
# Proguard configuration for Jackson 2.x
-keep class com.fasterxml.jackson.databind.ObjectMapper {
public <methods>;
protected <methods>;
}
-keep class com.fasterxml.jackson.databind.ObjectWriter {
public ** writeValueAsString(**);
}
-keepnames class com.fasterxml.jackson.** { *; }
-dontwarn com.fasterxml.jackson.databind.**
@CCorrado thank you for sharing this. I'll add it on:
https://github.com/FasterXML/jackson-docs/wiki/JacksonOnAndroid
Most helpful comment
Completely agree @cowtowncoder, however...
From personal experience, I have to set aside an entire day before pushing to production to just deal with proguard errors because so many libraries simply offer such broad rules instead of a real solution. So I have to manually dissect each warning and traverse the inner workings of every single library to figure out which ones I have to
-keepand which ones I can-dontwarn.Just my 2 cents 馃槃