问题描述
我刚刚开始使用AutoValue,但无法使其与proguard一起使用.我有大约6000多个这样的警告
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
实际错误表明了这一点...
The actually errors shows this...
我该如何解决此问题?
推荐答案
修复
之所以发生这种情况,是因为您已将库添加为项目的compile
依赖项.像这样:
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'
}
您需要使库成为provided
依赖项:
You need to make the library a provided
dependency:
dependencies {
provided 'com.google.auto.value:auto-value:1.2'
}
注意:provided
配置由Android Gradle插件提供.如果您在纯Java库模块中使用AutoValue,请使用 compileOnly 配置,已在Gradle 2.12中添加.
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.
AutoValue是一个为您生成代码的库.您与库本身的唯一交互应通过带有RetentionPolicy.SOURCE
的@AutoValue
批注-即它们仅在您的源代码中可用,而在编译后的代码中不可用.
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.
这意味着您的已编译代码与AutoValue库代码都没有任何关系.因此,无需使用您的代码进行编译-ProGuard运行该代码.
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.
这篇关于具有自动值的Proguard的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!