在android中运行proguard时,Jackson.jar出错

时间:2013-06-15 04:13:21

标签: android jackson proguard

我有一个使用jackson-all-1.7.2.jar的android项目。

当我使用这个proguard.cfg文件运行proguard时:

-keep class com.actionbarsherlock.** {*;}
-keep class org.holoeverywhere.** {*;}

-libraryjars /libs/jackson-all-1.7.2.jar

我遇到了这个例外:

[2013-06-15 06:06:04 - ArrowAndroid] Proguard returned with error code 1. See console
[2013-06-15 06:06:04 - ArrowAndroid] Note: there were 600 duplicate class definitions.
[2013-06-15 06:06:04 - ArrowAndroid] Warning: org.codehaus.jackson.jaxrs.JacksonJsonProvider: can't find superclass or interface javax.ws.rs.ext.MessageBodyReader
[2013-06-15 06:06:04 - ArrowAndroid] Warning: org.codehaus.jackson.jaxrs.JacksonJsonProvider: can't find superclass or interface javax.ws.rs.ext.MessageBodyWriter
[2013-06-15 06:06:04 - ArrowAndroid] Warning: org.codehaus.jackson.jaxrs.JsonMappingExceptionMapper: can't find superclass or interface javax.ws.rs.ext.ExceptionMapper
[2013-06-15 06:06:04 - ArrowAndroid] Warning: org.codehaus.jackson.jaxrs.JsonParseExceptionMapper: can't find superclass or interface javax.ws.rs.ext.ExceptionMapper
[2013-06-15 06:06:04 - ArrowAndroid] Warning: org.codehaus.jackson.xc.DataHandlerJsonDeserializer$1: can't find superclass or interface javax.activation.DataSource
[2013-06-15 06:06:04 - ArrowAndroid] Warning: org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider: can't find referenced class javax.ws.rs.ext.Provider
[2013-06-15 06:06:04 - ArrowAndroid] Warning: org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider: can't find referenced class javax.ws.rs.Consumes
[2013-06-15 06:06:04 - ArrowAndroid] Warning: org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider: can't find referenced class javax.ws.rs.Produces
[2013-06-15 06:06:04 - ArrowAndroid] Warning: org.codehaus.jackson.jaxrs.JacksonJsonProvider: can't find referenced class javax.ws.rs.core.MediaType
[2013-06-15 06:06:04 - ArrowAndroid] Warning: org.codehaus.jackson.jaxrs.JacksonJsonProvider: can't find referenced class javax.ws.rs.ext.Providers
[2013-06-15 06:06:04 - ArrowAndroid] Warning: org.codehaus.jackson.jaxrs.JacksonJsonProvider: can't find referenced class javax.ws.rs.ext.ContextResolver
[2013-06-15 06:06:04 - ArrowAndroid] Warning: org.codehaus.jackson.jaxrs.JacksonJsonProvider: can't find referenced class javax.ws.rs.core.StreamingOutput
[2013-06-15 06:06:04 - ArrowAndroid] Warning: org.codehaus.jackson.jaxrs.JacksonJsonProvider: can't find referenced class javax.ws.rs.core.Response
[2013-06-15 06:06:04 - ArrowAndroid] Warning: org.codehaus.jackson.jaxrs.JacksonJsonProvider: can't find referenced class javax.ws.rs.ext.MessageBodyReader
[2013-06-15 06:06:04 - ArrowAndroid] Warning: org.codehaus.jackson.jaxrs.JacksonJsonProvider: can't find referenced class javax.ws.rs.ext.MessageBodyWriter
[2013-06-15 06:06:04 - ArrowAndroid] Warning: org.codehaus.jackson.jaxrs.JacksonJsonProvider: can't find referenced class javax.ws.rs.core.MediaType
[2013-06-15 06:06:04 - ArrowAndroid] Warning: org.codehaus.jackson.jaxrs.JacksonJsonProvider: can't find referenced class javax.ws.rs.ext.Providers
.....
.....
.....
[2013-06-15 06:06:04 - ArrowAndroid]       You should check if you need to specify additional program jars.
[2013-06-15 06:06:04 - ArrowAndroid] Warning: there were 387 unresolved references to classes or interfaces.
[2013-06-15 06:06:04 - ArrowAndroid]          You may need to specify additional library jars (using '-libraryjars').
[2013-06-15 06:06:04 - ArrowAndroid] java.io.IOException: Please correct the above warnings first.
[2013-06-15 06:06:04 - ArrowAndroid]    at proguard.Initializer.execute(Initializer.java:321)
[2013-06-15 06:06:04 - ArrowAndroid]    at proguard.ProGuard.initialize(ProGuard.java:211)
[2013-06-15 06:06:04 - ArrowAndroid]    at proguard.ProGuard.execute(ProGuard.java:86)
[2013-06-15 06:06:04 - ArrowAndroid]    at proguard.ProGuard.main(ProGuard.java:492)

请注意,该应用程序在没有proguard的情况下运行良好。

当我在proguard.cfg中添加以下行时 -dontwarn org.codehaus.jackson

应用崩溃报告此异常:

Caused by: java.lang.ExceptionInInitializerError
    at org.codehaus.jackson.map.ObjectMapper.<clinit>(Unknown Source)
    ... 15 more
 Caused by: java.lang.NoSuchFieldError: PUBLIC_ONLY
    at java.lang.Class.getDeclaredAnnotation(Native Method)
    at java.lang.Class.getAnnotation(Class.java:260)
    at org.codehaus.jackson.map.introspect.VisibilityChecker$Std.<clinit>(Unknown Source)
    ... 16 more

2 个答案:

答案 0 :(得分:5)

文件jackson-all-1.7.2.jar已经在您的libs目录中,因此Android Ant / Eclipse构建将自动获取它。您不应该使用-libraryjars再次阅读它,因为这样您就会收到有关重复项的警告。

杰克逊正在使用反思来寻找一些注释。 ProGuard无法自动推断出这一点,最终会删除相关的,看似未使用的字段。这种配置应该保留它们:

-keepclassmembers public final enum org.codehaus.jackson.annotate.JsonAutoDetect$Visibility {
    public static final org.codehaus.jackson.annotate.JsonAutoDetect$Visibility *;
}

答案 1 :(得分:2)

在proguard配置文件中添加这些行。

-keepnames class com.fasterxml.jackson.** { 
*; 
}
-keepnames interface com.fasterxml.jackson.** { 
    *; 
}