Search code examples
androidspringjacksonproguardandroid-proguard

Proguard causes 100 "can't find referenced class" warnings, ignores keep rules for springframework and jackson


My code compiles and runs fine in debug mode, but once I use a build configuration with minifyEnabled true I get these warnings which prevent compilation:

Warning:there were 100 unresolved references to classes or interfaces.

Warning:there were 2 unresolved references to program class members.

For readabilities sake I'll include the full output at the bottom. There are two libraries that are causing these warnings, springframework and jackson. Those libraries are included in my project via gradle like so:

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'

If I use -dontwarn for both of these libraries, like many people suggest for these types of issues, the app compiles but crashes with an obfuscated crashlog during startup - I tried retracing it with the mapping file, but that's not working either - I'm reasonably certain that the app crashes due to the autogenerated (through android annotations) class RestClient_ when initializing a jackson mapping class, the exception is the following:

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)

Although on a different phone, the exception has no message. It's pretty obvious that this is a result of proguard.

My full proguard file can be found here https://gist.github.com/Syzygy2048/02a44032611d40720bad36b5e3b37db6


Here are a couple of things I already tried (I tried more, but I only started writing things down after a while). The attempts focus on fixing springframework first. (Had to put this in a gist because stackoverflow wouldn't let me post otherwise)

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


full error log:

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


Solution

  • It turns out that adding this to my proguard file fixed my issues.

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

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

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

    -dontwarn org.springframework.**

    So in the end I could ignore most of those warnings after all. As I said simply ignoring them lead to crashes, which are fixed by not obfuscating jackson annotations and by not obfuscating my model classes which seem to be needed so that the json <--> pojo conversion can happen.