Android使用Parse.com - 在Proguard

时间:2015-06-06 08:55:01

标签: android parse-platform proguard

我在项目中使用Parse。该项目使用我自己的Android库项目,其中包含Parse jar。当我尝试生成签名的apk时,gradle会出现以下问题:

  

:exampleApp:proguardRelease警告:   com.parse.ParseOkHttpClient $ CountingOkHttpRequestBody:找不到   超类或接口com.squareup.okhttp.RequestBody警告:   com.fasterxml.jackson.databind.ext.DOMSerializer:无法找到   引用类org.w3c.dom.bootstrap.DOMImplementationRegistry   警告:com.fasterxml.jackson.databind.ext.DOMSerializer:无法找到   引用类org.w3c.dom.bootstrap.DOMImplementationRegistry   警告:com.fasterxml.jackson.databind.ext.DOMSerializer:无法找到   引用类org.w3c.dom.bootstrap.DOMImplementationRegistry   警告:com.fasterxml.jackson.databind.ext.DOMSerializer:无法找到   引用类org.w3c.dom.bootstrap.DOMImplementationRegistry   警告:com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.OkHttpClient警告:com.parse.ParseOkHttpClient:   无法找到引用的类com.squareup.okhttp.OkHttpClient警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.OkHttpClient警告:com.parse.ParseOkHttpClient:   无法找到引用的类com.squareup.okhttp.OkHttpClient警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.OkHttpClient警告:com.parse.ParseOkHttpClient:   无法找到引用的类com.squareup.okhttp.OkHttpClient警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.OkHttpClient警告:com.parse.ParseOkHttpClient:   无法找到引用的类com.squareup.okhttp.OkHttpClient警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Call警告:com.parse.ParseOkHttpClient:可以&#t; t   找到引用的类com.squareup.okhttp.Response警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Response警告:com.parse.ParseOkHttpClient:   无法找到引用的类com.squareup.okhttp.ResponseBody警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.ResponseBody警告:com.parse.ParseOkHttpClient:   无法找到引用的类com.squareup.okhttp.Response警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Request $ Builder警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Request $ Builder警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Request $ Builder警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Request $ Builder警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Request $ Builder警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Headers $ Builder警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Headers $ Builder警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Headers $ Builder警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Headers $ Builder警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Request $ Builder警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Request $ Builder警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Request $ Builder警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Request $ Builder警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Response警告:com.parse.ParseOkHttpClient:   无法找到引用的类com.squareup.okhttp.Request $ Builder   警告:com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Headers $ Builder警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Headers警告:com.parse.ParseOkHttpClient:   无法找到引用的类com.squareup.okhttp.Call警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.ResponseBody警告:com.parse.ParseOkHttpClient:   无法找到引用的类com.squareup.okhttp.Request警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Headers警告:com.parse.ParseOkHttpClient:   无法找到引用的类com.squareup.okhttp.OkHttpClient警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Request警告:com.parse.ParseOkHttpClient:   无法找到引用的类com.squareup.okhttp.Call警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Response警告:com.parse.ParseOkHttpClient:   无法找到引用的类com.squareup.okhttp.Call警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Call警告:com.parse.ParseOkHttpClient:可以&#t; t   找到引用的类com.squareup.okhttp.Response警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Response警告:com.parse.ParseOkHttpClient:   无法找到引用的类com.squareup.okhttp.Request警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Request $ Builder警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Headers $ Builder警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Headers警告:com.parse.ParseOkHttpClient:   无法找到引用的类com.squareup.okhttp.Request警告:   com.parse.ParseOkHttpClient:无法找到引用的类   com.squareup.okhttp.Response警告:com.parse.ParseOkHttpClient $ 1:   无法找到引用的类com.squareup.okhttp.Call警告:   com.parse.ParseOkHttpClient $ 1:无法找到引用的类   com.squareup.okhttp.Call警告:com.parse.ParseOkHttpClient $ 1:可以&#t; t   找到引用的类com.squareup.okhttp.Call警告:   com.parse.ParseOkHttpClient $ 1:无法找到引用的类   com.squareup.okhttp.Call警告:   com.parse.ParseOkHttpClient $ CountingOkHttpRequestBody:找不到   引用类com.squareup.okhttp.RequestBody警告:   com.parse.ParseOkHttpClient $ CountingOkHttpRequestBody:找不到   引用类com.squareup.okhttp.MediaType警告:   com.parse.ParseOkHttpClient $ CountingOkHttpRequestBody:找不到   引用类okio.BufferedSink警告:   com.parse.ParseOkHttpClient $ CountingOkHttpRequestBody:找不到   引用类com.squareup.okhttp.RequestBody警告:   com.parse.ParseOkHttpClient $ CountingOkHttpRequestBody:找不到   引用类com.squareup.okhttp.MediaType警告:   com.parse.ParseOkHttpClient $ CountingOkHttpRequestBody:找不到   引用类okio.BufferedSink警告:   com.parse.ParseOkHttpClient $ CountingOkHttpRequestBody:找不到   引用类com.squareup.okhttp.MediaType警告:   com.parse.ParseOkHttpClient $ CountingOkHttpRequestBody:找不到   引用类okio.BufferedSink警告:   com.parse.ParseOkHttpClient $ CountingOkHttpRequestBody:找不到   引用类okio.BufferedSink警告:有67个未解决   对类或接口的引用。            您可能需要添加缺少的库jar或更新其版本。            如果您的代码工作正常而没有丢失的类,则可以禁止            警告' -dontwarn'选项。            (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)   :exampleApp:proguardRelease FAILED

     

失败:构建因异常而失败。

编辑: 根据@ karama的建议,我将此添加到我的计划规则中:

-keepattributes *Annotation*
-keepattributes Signature
-dontwarn com.squareup.**
-keep class com.squareup.** { *; }

-dontwarn com.parse.ParseOkHttpClient**
-keep class com.parse.ParseOkHttpClient** { *; }

# Proguard configuration for Jackson 2.x (fasterxml package instead of codehaus package)
-keep class com.fasterxml.jackson.databind.ObjectMapper {
    public <methods>;
    protected <methods>;
}
-keep class com.fasterxml.jackson.databind.ObjectWriter {
    public ** writeValueAsString(**);
}
-dontwarn org.w3c.dom.bootstrap.DOMImplementationRegistry

然而,现在我得到以下内容:

  

警告:com.fasterxml.jackson.databind.ext.DOMSerializer:无法找到   引用类org.w3c.dom.bootstrap.DOMImplementationRegistry   警告:com.fasterxml.jackson.databind.ext.DOMSerializer:无法找到   引用类org.w3c.dom.bootstrap.DOMImplementationRegistry   警告:com.fasterxml.jackson.databind.ext.DOMSerializer:无法找到   引用类org.w3c.dom.bootstrap.DOMImplementationRegistry   警告:com.fasterxml.jackson.databind.ext.DOMSerializer:无法找到   引用类org.w3c.dom.bootstrap.DOMImplementationRegistry   警告:com.fasterxml.jackson.databind.ext.DOMSerializer:无法找到   引用类org.w3c.dom.bootstrap.DOMImplementationRegistry   警告:有5个未解析的类或接口引用。

如果我通过添加修复它: -dontwarn org.w3c.dom.bootstrap.DOMImplementationRegistry 当应用程序运行时,它会崩溃。我在这里看到了这个问题,但没有解决方案:https://stackoverflow.com/a/11249755/197127

使用-dontobfuscate运行应用程序正常。

1 个答案:

答案 0 :(得分:4)

该错误不是解析sdk,因为okHttp而发生。在你的proguard中添加以下行。

-keepattributes *Annotation*
-keepattributes Signature
-dontwarn com.squareup.**
-keep class com.squareup.** { *; }

修改

为com.fasterxml.jackson添加以下代码:

-keep class com.fasterxml.jackson.databind.ObjectMapper {
    public <methods>;
    protected <methods>;
}
-keep class com.fasterxml.jackson.databind.ObjectWriter {
    public ** writeValueAsString(**);
}

参考:https://github.com/krschultz/android-proguard-snippets/issues/19