具有自动值的Proguard [英] Proguard with Autovalue

查看:71
本文介绍了具有自动值的Proguard的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用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

警告:autovalue.shaded.com.google.common.auto.common.MoreElements $ 1:找不到超类或接口javax.lang.model.util.SimpleElementVisitor6

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...

错误:任务执行失败 ':transformClassesAndResourcesWithProguardForDebug'. java.io.IOException:请首先更正以上警告.

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

我该如何解决此问题?

推荐答案

修复

之所以发生这种情况,是因为您已将库添加为项目的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,请使用

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆