Proguard 导致 100 "can't find referenced class" 条警告,忽略 springframework 和 jackson 的保留规则
Proguard causes 100 "can't find referenced class" warnings, ignores keep rules for springframework and jackson
我的代码在调试模式下编译和运行良好,但是一旦我使用带有 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,就像许多人针对这些类型的问题所建议的那样,该应用程序会编译但在启动期间因混淆的崩溃日志而崩溃 - 我尝试使用映射文件对其进行追溯,但事实并非如此工作 - 我有理由确定应用程序由于自动生成(通过 android 注释)class RestClient_ 在初始化杰克逊映射 class 时崩溃,异常如下:
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)
虽然在不同的 phone 上,但异常没有消息。很明显这是proguard的结果。
我的完整混淆文件可以在这里找到https://gist.github.com/Syzygy2048/02a44032611d40720bad36b5e3b37db6
这里有一些我已经尝试过的东西(我尝试了更多,但我只是在一段时间后才开始写下来)。这些尝试着重于首先修复 springframework。 (不得不把它放在一个要点中,因为 Whosebug 不会让我 post 否则)
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 转换可以发生.
我的代码在调试模式下编译和运行良好,但是一旦我使用带有 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,就像许多人针对这些类型的问题所建议的那样,该应用程序会编译但在启动期间因混淆的崩溃日志而崩溃 - 我尝试使用映射文件对其进行追溯,但事实并非如此工作 - 我有理由确定应用程序由于自动生成(通过 android 注释)class RestClient_ 在初始化杰克逊映射 class 时崩溃,异常如下:
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)
虽然在不同的 phone 上,但异常没有消息。很明显这是proguard的结果。
我的完整混淆文件可以在这里找到https://gist.github.com/Syzygy2048/02a44032611d40720bad36b5e3b37db6
这里有一些我已经尝试过的东西(我尝试了更多,但我只是在一段时间后才开始写下来)。这些尝试着重于首先修复 springframework。 (不得不把它放在一个要点中,因为 Whosebug 不会让我 post 否则)
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 转换可以发生.