Proguard with Autovalue

感情迁移 提交于 2019-12-05 21:00:02

问题


I have just started using AutoValue but I am unable to make it work with proguard. I have around 6000+ warnings that look like this

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

The actually errors shows this...

Error:Execution failed for task ':transformClassesAndResourcesWithProguardForDebug'. java.io.IOException: Please correct the above warnings first.

How can i resolve this issue?


回答1:


The fix

This is happening since you have added the library as a compile dependency of your project. Something like this:

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

You need to make the library a provided dependency:

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

Note: The provided configuration is made available by the Android Gradle plugin. If you're using AutoValue in a pure Java library module, use the compileOnly configuration, added in Gradle 2.12.

The explanation

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

This means that your compiled code has no connection to the AutoValue library code whatsoever. So, it doesn't need to to compiled with your code - which is the code ProGuard runs on.



来源:https://stackoverflow.com/questions/36428868/proguard-with-autovalue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!