Proguard with Autovalue

I just started using AutoValue, but I can't get it to work with proguard. I have about 6000+ warnings that look like this:

Warning: autovalue.shaded.com.google.common.auto.common.MoreElements $ 1: cannot find superclass or interface javax.lang.model.util.SimpleElementVisitor6

In fact, errors show this ...

Error: execution completed for task ': TransformClassesAndResourcesWithProguardForDebug'. java.io.IOException: First, follow the warnings above.

How can I solve this problem?

+8
android proguard android-proguard auto-value
source share
1 answer

Correction

This happens because you added the library as a compile dependency of your project. Something like that:

 dependencies { compile 'com.google.auto.value:auto-value:1.2' } 

You need to make the library dependent provided :

 dependencies { provided 'com.google.auto.value:auto-value:1.2' } 

Note. The provided configuration is available for the Android Gradle plugin. If you use AutoValue in a pure Java library module, use the compileOnly configuration added in Gradle 2.12.

Explanation

AutoValue is a library that generates code for you. Your only interaction with the library itself should be through @AutoValue annotations, which have RetentionPolicy.SOURCE - that is, they are available only in the source code, not in the compiled code.

This means that your compiled code has nothing to do with the code in the AutoValue library. Thus, it does not need to be compiled using your code - it is ProGuard code.

+12
source share

All Articles