尽管上课,仍然会有警告 [英] Proguard warnings despite kept classes

查看:145
本文介绍了尽管上课,仍然会有警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Proguard缩小我的代码。我的策略是启用它,然后按照警告来保留它抱怨的任何内容。如果有外部库,我会尝试按照作者提供的Proguard说明进行操作。许多说明包括 -dontwarn 标志。如果我禁用 -dontwarn 标志,我会收到警告。如果我们通过 -keep 标记保留大多数课程,为什么还会出现警告?
示例:

I'm using Proguard to shrink my code. My strategy is to enable it and then follow the warnings to keep anything it complains about. If there are outside libraries, I try to follow the Proguard instructions the authors make available. Many instructions include a -dontwarn flag. If I disable the -dontwarn flag, I will get warnings. If we are keeping most classes via -keep flag, why do warnings still come up? Example:

-keep class javax.** { *; }

# for butterknife
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }

-keepclasseswithmembernames class * {
    @butterknife.* <fields>;
}

-keepclasseswithmembernames class * {
    @butterknife.* <methods>;
}

Warning:butterknife.internal.ButterKnifeProcessor: can't find referenced class javax.annotation.processing.AbstractProcessor
Warning:butterknife.internal.ButterKnifeProcessor: can't find referenced class javax.annotation.processing.ProcessingEnvironment
Warning:butterknife.internal.ButterKnifeProcessor: can't find referenced class javax.lang.model.element.TypeElement
Warning:butterknife.internal.ButterKnifeProcessor: can't find referenced class javax.lang.model.element.Element
Warning:butterknife.internal.ButterKnifeProcessor: can't find referenced class javax.annotation.processing.Filer
Warning:butterknife.internal.ButterKnifeProcessor: can't find referenced class javax.tools.JavaFileObject
...


推荐答案

ProGuard中有很多警告意味着不同的东西。这个特别的一个:

There are many warnings in ProGuard meaning different things. This particular one:

Warning:A: can't find referenced class B

意味着当ProGuard处理A类时,它遇到了对B类的引用。但是B类并未作为源包含( -injars class_path )或作为库( -libraryjars class_path )。

Means that while ProGuard was processing class A it encountered reference to class B. But class B wasn't included as a source (-injars class_path) or as a library (-libraryjars class_path).

First请注意,对于此特定警告,如果标准Android构建链添加 -keep 规则将无济于事。 ProGuard传递性地保留了引用代码。

First note that for this particular warning in case of standard Android build chain adding -keep rules will not help. ProGuard transitively keeps referenced code.

出现这种警告有几个原因。库X通常可以包含使用另一个库Y的代码.X可选地使用Y - 只有当类路径中存在Y时,X才会强制存在Y.这样ProGuard无法从Y中找到类。
要删除警告,您必须添加Y作为依赖项或忽略相关警告。

This warning can happen for several reasons. Often a library X can contain code that uses another library Y. And X uses Y optionally - only when Y is present on the classpath, X doesn't enforce presence of Y. This way ProGuard is unable to find classes from Y. To get rid of the warnings you have to either add Y as a dependency or ignore the relevant warnings.

如果是ButterKnife,情况会略有不同。 Butterknife使用注释处理。它包含一个依赖项中的库和注释处理器(最新版本7.0.1)。所以类 butterknife.internal.ButterKnifeProcessor 仍然存在于已编译的类中(即使它的工作已经完成 - 在java编译期间使用)。 ProGuard尝试处理它。 ProGuard无法找到缺失的类,因为它们仅在注释处理期间使用,并且不适用于ProGuard处理。
在这种情况下,必须忽略警告。

In case of ButterKnife the situation is slightly different. Butterknife uses annotation processing. And it contains both the library and annotation processor in one dependency (latest version 7.0.1). So class butterknife.internal.ButterKnifeProcessor is still present in the compiled classes (even though it's work is already finished - used during java compilation). And ProGuard tries to process it. ProGuard fails to find the missing classes because they were used only during annotation processing and are not present for ProGuard processing. In this case it's really necessary to ignore the warnings.

这篇关于尽管上课,仍然会有警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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