如何设置Jackson JSON处理器的PROGUARD?

我正在为我的app使用Jackson JSON处理器。包括这个使用

compile 'com.fasterxml.jackson.core:jackson-databind:2.4.2' compile 'com.fasterxml.jackson.core:jackson-annotations:2.4.2'. 

我的proguard配置是。

 ## BEGIN -- Google Play Services proguard.txt -keep class * extends java.util.ListResourceBundle { protected java.lang.Object[][] getContents(); } # Keep SafeParcelable value, needed for reflection. This is required to support backwards # compatibility of some classes. -keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable { public static final *** NULL; } # Keep the names of classes/members we need for client functionality. -keepnames @com.google.android.gms.common.annotation.KeepName class * -keepclassmembernames class * { @com.google.android.gms.common.annotation.KeepName *; } # Needed for Parcelable/SafeParcelable Creators to not get stripped -keepnames class * implements android.os.Parcelable { public static final ** CREATOR; } ## END -- Google Play Services proguard.txt -keepattributes Signature,RuntimeVisibleAnnotations,AnnotationDefault -dontskipnonpubliclibraryclassmembers -dontskipnonpubliclibraryclasses -keepattributes *Annotation*. -keep class org.codehaus.jackson.** -dontwarn twitter4j.** -dontwarn com.facebook.android.BuildConfig -dontwarn org.apache.commons.** -keep class org.apache.http.** { *; } -dontwarn org.apache.http.** -dontwarn com.nhaarman.listviewanimations.** 

但是,当我尝试在调试模式下编译时,我收到以下错误。

 26207-26207/com.blah E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.blah, PID: 26207 java.lang.NoSuchFieldError: PUBLIC_ONLY at java.lang.Class.getDeclaredAnnotation(Native Method) at java.lang.Class.getAnnotation(Class.java:290) at com.bacfah.(Unknown Source) at com.bacz(Unknown Source) at com.blah.utils.c.(Unknown Source) at com.blah.main.aa(Unknown Source) at com.blah.main.baa(Unknown Source) at com.blah.main.baonCreateView(Unknown Source) 

在此工作很长时间!非常感谢你的帮助!谢谢!

Solutions Collecting From Web of "如何设置Jackson JSON处理器的PROGUARD?"

经过多次调试后终于find了我的Proguard配置的答案

 -keepattributes *Annotation*,EnclosingMethod,Signature -keepnames class com.fasterxml.jackson.** { *; } -dontwarn com.fasterxml.jackson.databind.** -keep class org.codehaus.** { *; } -keepclassmembers public final enum org.codehaus.jackson.annotate.JsonAutoDetect$Visibility { public static final org.codehaus.jackson.annotate.JsonAutoDetect$Visibility *; } -keep public class your.class.** { public void set*(***); public *** get*(); } 

您的类描述了用于解析响应的getter setter类/类。

compile 'com.fasterxml.jackson.core:jackson-core:2.4.2'到我以前遗失的Gradle文件中。 现在我的Proguard像野兽一样工作.. 😉

修改了@goonerDroid为我工作的litte

 -keepattributes *Annotation*,EnclosingMethod,Signature -keepnames class com.fasterxml.jackson.** { *; } -dontwarn com.fasterxml.jackson.databind.** -keep class org.codehaus.** { *; } -keepclassmembers public final enum org.codehaus.jackson.annotate.JsonAutoDetect$Visibility { public static final org.codehaus.jackson.annotate.JsonAutoDetect$Visibility *; } -keep public class your.class.** { *; }