我的代码在 Debug模式下编译和运行良好,但是一旦我使用带有 minifyEnabled true 的构建配置,我就会收到这些阻止编译的警告:
Warning:there were 100 unresolved references to classes or interfaces.
Warning:there were 2 unresolved references to program class members.
为了便于阅读,我将在底部包含完整的输出。 有两个库导致这些警告,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: No static field PUBLIC_ONLY of type Lcom/myapp/app/mv$a; in class Lcom/myapp/app/mv$a; or its superclasses (declaration of 'com.myapp.app.mv$a' appears in /data/app/com.myapp.app-1/base.apk)
虽然在不同的手机上,异常没有消息。很明显,这是 proguard 的结果。
我的完整混淆文件可以在这里找到https://gist.github.com/Syzygy2048/02a44032611d40720bad36b5e3b37db6
这里有一些我已经尝试过的东西(我尝试了更多,但过了一段时间我才开始写下来)。这些尝试着重于首先修复 springframework。 (不得不把它放在一个要点中,因为 stackoverflow 不允许我以其他方式发布)
https://gist.github.com/Syzygy2048/f1bdabc9f2ea091aa8faec67c62dd8bb
完整错误日志:
Information:Gradle tasks [:myappApp:assembleMyappPublicRelease] Warning:org.springframework.core.convert.support.ConvertingPropertyEditorAdapter: can't find superclass or interface java.beans.PropertyEditorSupport Warning:com.fasterxml.jackson.databind.ext.DOMSerializer: can't find referenced class org.w3c.dom.bootstrap.DOMImplementationRegistry Warning:com.fasterxml.jackson.databind.ext.Java7SupportImpl: can't find referenced class java.beans.Transient Warning:com.fasterxml.jackson.databind.ext.Java7SupportImpl: can't find referenced class java.beans.ConstructorProperties Warning:com.fasterxml.jackson.databind.ext.Java7SupportImpl: can't find referenced class java.nio.file.Path Warning:com.fasterxml.jackson.databind.ext.Java7SupportImpl: can't find referenced class java.beans.Transient Warning:com.fasterxml.jackson.databind.ext.Java7SupportImpl: can't find referenced class java.beans.ConstructorProperties Warning:com.fasterxml.jackson.databind.ext.Java7SupportImpl: can't find referenced class java.beans.Transient Warning:com.fasterxml.jackson.databind.ext.Java7SupportImpl: can't find referenced class java.beans.ConstructorProperties Warning:com.fasterxml.jackson.databind.ext.Java7SupportImpl: can't find referenced class java.beans.Transient Warning:com.fasterxml.jackson.databind.ext.Java7SupportImpl: can't find referenced class java.beans.ConstructorProperties Warning:com.fasterxml.jackson.databind.ext.NioPathDeserializer: can't find referenced class java.nio.file.Path Warning:com.fasterxml.jackson.databind.ext.NioPathDeserializer: can't find referenced class java.nio.file.Paths Warning:com.fasterxml.jackson.databind.ext.NioPathDeserializer: can't find referenced class java.nio.file.Path Warning:com.fasterxml.jackson.databind.ext.NioPathSerializer: can't find referenced class java.nio.file.Path Warning:org.springframework.core.convert.support.ConvertingPropertyEditorAdapter: can't find referenced class java.beans.PropertyEditorSupport Warning:org.springframework.core.convert.support.ConvertingPropertyEditorAdapter: can't find referenced method 'void setValue(java.lang.Object)' in program class org.springframework.core.convert.support.ConvertingPropertyEditorAdapter Warning:org.springframework.core.convert.support.ConvertingPropertyEditorAdapter: can't find referenced method 'java.lang.Object getValue()' in program class org.springframework.core.convert.support.ConvertingPropertyEditorAdapter Warning:org.springframework.core.convert.support.ConvertingPropertyEditorAdapter: can't find referenced class java.beans.PropertyEditorSupport Warning:org.springframework.http.client.HttpComponentsClientHttpRequest: can't find referenced class org.apache.http.entity.ByteArrayEntityHC4 Warning:org.springframework.http.client.HttpComponentsClientHttpRequest: can't find referenced class org.apache.http.impl.client.CloseableHttpClient Warning:org.springframework.http.client.HttpComponentsClientHttpRequest: can't find referenced class org.apache.http.client.methods.CloseableHttpResponse Warning:org.springframework.http.client.HttpComponentsClientHttpRequestFactory: can't find referenced class org.apache.http.impl.client.HttpClients Warning:org.springframework.http.client.HttpComponentsClientHttpRequestFactory: can't find referenced class org.apache.http.impl.client.CloseableHttpClient Warning:org.springframework.http.client.HttpComponentsClientHttpRequestFactory: can't find referenced class org.apache.http.client.protocol.HttpClientContext Warning:org.springframework.http.client.HttpComponentsClientHttpRequestFactory: can't find referenced class org.apache.http.client.methods.Configurable Warning:org.springframework.http.client.HttpComponentsClientHttpRequestFactory: can't find referenced class org.apache.http.client.config.RequestConfig Warning:org.springframework.http.client.HttpComponentsClientHttpRequestFactory: can't find referenced class org.apache.http.client.config.RequestConfig$Builder Warning:org.springframework.http.client.HttpComponentsClientHttpRequestFactory: can't find referenced class org.apache.http.client.config.RequestConfig Warning:org.springframework.http.client.HttpComponentsClientHttpRequestFactory: can't find referenced class org.apache.http.client.methods.HttpGetHC4 Warning:org.springframework.http.client.HttpComponentsClientHttpRequestFactory: can't find referenced class org.apache.http.client.methods.HttpDeleteHC4 Warning:org.springframework.http.client.HttpComponentsClientHttpRequestFactory: can't find referenced class org.apache.http.client.methods.HttpHeadHC4 Warning:org.springframework.http.client.HttpComponentsClientHttpRequestFactory: can't find referenced class org.apache.http.client.methods.HttpOptionsHC4 Warning:org.springframework.http.client.HttpComponentsClientHttpRequestFactory: can't find referenced class org.apache.http.client.methods.HttpPostHC4 Warning:org.springframework.http.client.HttpComponentsClientHttpRequestFactory: can't find referenced class org.apache.http.client.methods.HttpPutHC4 Warning:org.springframework.http.client.HttpComponentsClientHttpRequestFactory: can't find referenced class org.apache.http.client.methods.HttpTraceHC4 Warning:org.springframework.http.client.HttpComponentsClientHttpRequestFactory: can't find referenced class org.apache.http.client.methods.HttpPatch Warning:org.springframework.http.client.HttpComponentsClientHttpRequestFactory: can't find referenced class org.apache.http.impl.client.CloseableHttpClient Warning:org.springframework.http.client.HttpComponentsClientHttpRequestFactory: can't find referenced class org.apache.http.client.config.RequestConfig Warning:org.springframework.http.client.HttpComponentsClientHttpRequestFactory: can't find referenced class org.apache.http.impl.client.HttpClients Warning:org.springframework.http.client.HttpComponentsClientHttpRequestFactory: can't find referenced class org.apache.http.client.protocol.HttpClientContext Warning:org.springframework.http.client.HttpComponentsClientHttpRequestFactory: can't find referenced class org.apache.http.client.config.RequestConfig Warning:org.springframework.http.client.HttpComponentsClientHttpRequestFactory: can't find referenced class org.apache.http.client.config.RequestConfig$Builder Warning:org.springframework.http.client.HttpComponentsClientHttpRequestFactory: can't find referenced class org.apache.http.impl.client.CloseableHttpClient Warning:org.springframework.http.client.HttpComponentsClientHttpRequestFactory: can't find referenced class org.apache.http.client.config.RequestConfig Warning:org.springframework.http.client.HttpComponentsClientHttpRequestFactory: can't find referenced class org.apache.http.impl.client.CloseableHttpClient Warning:org.springframework.http.client.HttpComponentsClientHttpResponse: can't find referenced class org.apache.http.client.methods.CloseableHttpResponse Warning:org.springframework.http.client.HttpComponentsClientHttpResponse: can't find referenced class org.apache.http.util.EntityUtilsHC4 Warning:org.springframework.http.client.HttpComponentsClientHttpResponse: can't find referenced class org.apache.http.client.methods.CloseableHttpResponse Warning:org.springframework.http.client.HttpComponentsClientHttpResponse: can't find referenced class org.apache.http.util.EntityUtilsHC4 Warning:org.springframework.http.client.HttpComponentsClientHttpResponse: can't find referenced class org.apache.http.client.methods.CloseableHttpResponse Warning:org.springframework.http.client.HttpComponentsStreamingClientHttpRequest: can't find referenced class org.apache.http.impl.client.CloseableHttpClient Warning:org.springframework.http.client.HttpComponentsStreamingClientHttpRequest: can't find referenced class org.apache.http.client.methods.CloseableHttpResponse Warning:org.springframework.http.converter.xml.SimpleXmlHttpMessageConverter: can't find referenced class org.simpleframework.xml.core.Persister Warning:org.springframework.http.converter.xml.SimpleXmlHttpMessageConverter: can't find referenced class org.simpleframework.xml.Root Warning:org.springframework.http.converter.xml.SimpleXmlHttpMessageConverter: can't find referenced class org.simpleframework.xml.Serializer Warning:there were 100 unresolved references to classes or interfaces. Warning:there were 2 unresolved references to program class members. Warning:Exception while processing task java.io.IOException: Please correct the above warnings first. Error:Execution failed for task ':myappApp:transformClassesAndResourcesWithProguardForMyappPublicRelease'. Job failed, see logs for details Information:BUILD FAILED Information:Total time: 23.68 secs Information:1 error Information:59 warnings Information:See complete output in console
最佳答案
事实证明,将它添加到我的混淆文件中解决了我的问题。
-keepclassmembers class com.myapp.models.** { *; }
-keep class com.fasterxml.jackson.annotation.** { *; }
-dontwarn com.fasterxml.jackson.databind.**
-dontwarn org.springframework.**
所以最后我可以忽略大部分警告。正如我所说,简单地忽略它们会导致崩溃,这通过不混淆 jackson 注释和不混淆我的模型类来解决,这似乎是必要的,以便 json <--> pojo 转换可以发生。
关于android - Proguard causes 100 "can' t find referenced class"警告,忽略 springframework 和 jackson 的保留规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41757975/