Proguard导致100"无法找到引用的类"警告,忽略了springframework和jackson

时间:2017-01-20 07:11:50

标签: android spring jackson proguard android-proguard

我的代码在调试模式下编译并运行良好,但是一旦我使用minifyEnabled的构建配置为true,我会收到这些警告,这会阻止编译:

  

警告:有100个未解析的类或接口引用。

     

警告:程序类成员有2个未解析的引用。

为了便于阅读,我将在底部包含完整输出。 有两个库导致这些警告,springframework和jackson。这些库通过gradle包含在我的项目中,如下所示:

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

apt "org.androidannotations:rest-spring:$AAVersion"
compile "org.androidannotations:rest-spring-api:$AAVersion"     
compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3'

如果我对这两个库使用-dontwarn,就像许多人建议的这些类型的问题一样,应用程序编译但在启动时遇到混乱的崩溃日志崩溃 - 我尝试用映射文件回溯它,但是那个'也没有工作 - 我合理地确定应用程序在初始化jackson映射类时由于自动生成(通过android注释)类RestClient_而崩溃,例外情况如下:

  

java.lang.NoSuchFieldError:没有类型的静态字段PUBLIC_ONLY   LCOM / MyApp的/应用/ MV $一个;在课堂Lcom / myapp / app / mv $ a;或者它的超类   (声明' com.myapp.app.mv $ a'出现在   /data/app/com.myapp.app-1/base.apk)

虽然在另一部手机上,但该例外没有消息。很明显,这是proguard的结果。

我的完整proguard文件可以在https://gist.github.com/Syzygy2048/02a44032611d40720bad36b5e3b37db6

找到

以下是我已经尝试过的一些事情(我尝试了更多,但过了一段时间我才开始写下来)。尝试的重点是首先修复弹簧框架。 (不得不把它放在一个要点,因为stackoverflow不会让我发布其他内容)

https://gist.github.com/Syzygy2048/f1bdabc9f2ea091aa8faec67c62dd8bb

完整错误日志:

  

信息:Gradle任务[:myappApp:assembleMyappPublicRelease]   警告:org.springframework.core.convert.support.ConvertingPropertyEditorAdapter:无法找到超类或接口java.beans.PropertyEditorSupport   警告:com.fasterxml.jackson.databind.ext.DOMSerializer:找不到引用的类org.w3c.dom.bootstrap.DOMImplementationRegistry   警告:com.fasterxml.jackson.databind.ext.Java7SupportImpl:无法找到引用的类java.beans.Transient   警告:com.fasterxml.jackson.databind.ext.Java7SupportImpl:无法找到引用的类java.beans.ConstructorProperties   警告:com.fasterxml.jackson.databind.ext.Java7SupportImpl:无法找到引用的类java.nio.file.Path   警告:com.fasterxml.jackson.databind.ext.Java7SupportImpl:无法找到引用的类java.beans.Transient   警告:com.fasterxml.jackson.databind.ext.Java7SupportImpl:无法找到引用的类java.beans.ConstructorProperties   警告:com.fasterxml.jackson.databind.ext.Java7SupportImpl:无法找到引用的类java.beans.Transient   警告:com.fasterxml.jackson.databind.ext.Java7SupportImpl:无法找到引用的类java.beans.ConstructorProperties   警告:com.fasterxml.jackson.databind.ext.Java7SupportImpl:无法找到引用的类java.beans.Transient   警告:com.fasterxml.jackson.databind.ext.Java7SupportImpl:无法找到引用的类java.beans.ConstructorProperties   警告:com.fasterxml.jackson.databind.ext.NioPathDeserializer:找不到引用的类java.nio.file.Path   警告:com.fasterxml.jackson.databind.ext.NioPathDeserializer:找不到引用的类java.nio.file.Paths   警告:com.fasterxml.jackson.databind.ext.NioPathDeserializer:找不到引用的类java.nio.file.Path   警告:com.fasterxml.jackson.databind.ext.NioPathSerializer:找不到引用的类java.nio.file.Path   警告:org.springframework.core.convert.support.ConvertingPropertyEditorAdapter:找不到引用的类java.beans.PropertyEditorSupport   警告:org.springframework.core.convert.support.ConvertingPropertyEditorAdapter:无法找到引用的方法' void setValue(java.lang.Object)'在程序类org.springframework.core.convert.support.ConvertingPropertyEditorAdapter中   警告:org.springframework.core.convert.support.ConvertingPropertyEditorAdapter:找不到引用的方法' java.lang.Object getValue()'在程序类org.springframework.core.convert.support.ConvertingPropertyEditorAdapter中   警告:org.springframework.core.convert.support.ConvertingPropertyEditorAdapter:找不到引用的类java.beans.PropertyEditorSupport   警告:org.springframework.http.client.HttpComponentsClientHttpRequest:无法找到引用的类org.apache.http.entity.ByteArrayEntityHC4   警告:org.springframework.http.client.HttpComponentsClientHttpRequest:无法找到引用的类org.apache.http.impl.client.CloseableHttpClient   警告:org.springframework.http.client.HttpComponentsClientHttpRequest:无法找到引用的类org.apache.http.client.methods.CloseableHttpResponse   警告:org.springframework.http.client.HttpComponentsClientHttpRequestFactory:无法找到引用的类org.apache.http.impl.client.HttpClients   警告:org.springframework.http.client.HttpComponentsClientHttpRequestFactory:无法找到引用的类org.apache.http.impl.client.CloseableHttpClient   警告:org.springframework.http.client.HttpComponentsClientHttpRequestFactory:无法找到引用的类org.apache.http.client.protocol.HttpClientContext   警告:org.springframework.http.client.HttpComponentsClientHttpRequestFactory:无法找到引用的类org.apache.http.client.methods.Configurable   警告:org.springframework.http.client.HttpComponentsClientHttpRequestFactory:无法找到引用的类org.apache.http.client.config.RequestConfig   警告:org.springframework.http.client.HttpComponentsClientHttpRequestFactory:无法找到引用的类org.apache.http.client.config.RequestConfig $ Builder   警告:org.springframework.http.client.HttpComponentsClientHttpRequestFactory:无法找到引用的类org.apache.http.client.config.RequestConfig   警告:org.springframework.http.client.HttpComponentsClientHttpRequestFactory:无法找到引用的类org.apache.http.client.methods.HttpGetHC4   警告:org.springframework.http.client.HttpComponentsClientHttpRequestFactory:无法找到引用的类org.apache.http.client.methods.HttpDeleteHC4   警告:org.springframework.http.client.HttpComponentsClientHttpRequestFactory:无法找到引用的类org.apache.http.client.methods.HttpHeadHC4   警告:org.springframework.http.client.HttpComponentsClientHttpRequestFactory:无法找到引用的类org.apache.http.client.methods.HttpOptionsHC4   警告:org.springframework.http.client.HttpComponentsClientHttpRequestFactory:无法找到引用的类org.apache.http.client.methods.HttpPostHC4   警告:org.springframework.http.client.HttpComponentsClientHttpRequestFactory:无法找到引用的类org.apache.http.client.methods.HttpPutHC4   警告:org.springframework.http.client.HttpComponentsClientHttpRequestFactory:无法找到引用的类org.apache.http.client.methods.HttpTraceHC4   警告:org.springframework.http.client.HttpComponentsClientHttpRequestFactory:无法找到引用的类org.apache.http.client.methods.HttpPatch   警告:org.springframework.http.client.HttpComponentsClientHttpRequestFactory:无法找到引用的类org.apache.http.impl.client.CloseableHttpClient   警告:org.springframework.http.client.HttpComponentsClientHttpRequestFactory:无法找到引用的类org.apache.http.client.config.RequestConfig   警告:org.springframework.http.client.HttpComponentsClientHttpRequestFactory:无法找到引用的类org.apache.http.impl.client.HttpClients   警告:org.springframework.http.client.HttpComponentsClientHttpRequestFactory:无法找到引用的类org.apache.http.client.protocol.HttpClientContext   警告:org.springframework.http.client.HttpComponentsClientHttpRequestFactory:无法找到引用的类org.apache.http.client.config.RequestConfig   警告:org.springframework.http.client.HttpComponentsClientHttpRequestFactory:无法找到引用的类org.apache.http.client.config.RequestConfig $ Builder   警告:org.springframework.http.client.HttpComponentsClientHttpRequestFactory:无法找到引用的类org.apache.http.impl.client.CloseableHttpClient   警告:org.springframework.http.client.HttpComponentsClientHttpRequestFactory:无法找到引用的类org.apache.http.client.config.RequestConfig   警告:org.springframework.http.client.HttpComponentsClientHttpRequestFactory:无法找到引用的类org.apache.http.impl.client.CloseableHttpClient   警告:org.springframework.http.client.HttpComponentsClientHttpResponse:无法找到引用的类org.apache.http.client.methods.CloseableHttpResponse   警告:org.springframework.http.client.HttpComponentsClientHttpResponse:找不到引用的类org.apache.http.util.EntityUtilsHC4   警告:org.springframework.http.client.HttpComponentsClientHttpResponse:无法找到引用的类org.apache.http.client.methods.CloseableHttpResponse   警告:org.springframework.http.client.HttpComponentsClientHttpResponse:找不到引用的类org.apache.http.util.EntityUtilsHC4   警告:org.springframework.http.client.HttpComponentsClientHttpResponse:无法找到引用的类org.apache.http.client.methods.CloseableHttpResponse   警告:org.springframework.http.client.HttpComponentsStreamingClientHttpRequest:无法找到引用的类org.apache.http.impl.client.CloseableHttpClient   警告:org.springframework.http.client.HttpComponentsStreamingClientHttpRequest:无法找到引用的类org.apache.http.client.methods.CloseableHttpResponse   警告:org.springframework.http.converter.xml.SimpleXmlHttpMessageConverter:无法找到引用的类org.simpleframework.xml.core.Persister   警告:org.springframework.http.converter.xml.SimpleXmlHttpMessageConverter:找不到引用的类org.simpleframework.xml.Root   警告:org.springframework.http.converter.xml.SimpleXmlHttpMessageConverter:无法找到引用的类org.simpleframework.xml.Serializer   警告:有100个未解析的类或接口引用。   警告:程序类成员有2个未解析的引用。   警告:处理任务java.io.IOException时发生异常:请先纠正上述警告。   错误:任务':myappApp:transformClassesAndResourcesWithProguardForMyappPublicRelease'执行失败。   作业失败,请参阅日志了解详情   信息:建筑失败   信息:总时间:23.68秒   信息:1错误   信息:59个警告   信息:请参阅控制台中的完整输出

1 个答案:

答案 0 :(得分:5)

事实证明,将此添加到我的proguard文件修复了我的问题。

  

-keepclassmembers class com.myapp.models。** {       *; }

     

-keep class com.fasterxml.jackson.annotation。** {*; }

     

-dontwarn com.fasterxml.jackson.databind。**

     

-dontwarn org.springframework。**

所以最后我可以忽略大部分警告。正如我所说的那样,简单地忽略它们会导致崩溃,这些崩溃是通过不混淆杰克逊注释和不模糊我似乎需要的模型类来解决的,因此json< - > pojo转换可能发生。