我如何告诉 proguard 假设一个包没有被使用? [英] How can I tell proguard to assume a package is not used?

查看:20
本文介绍了我如何告诉 proguard 假设一个包没有被使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的 Android 项目设置 proguard.我们在代码中使用了一些 netty 库,我想使用 Proguard 完全删除我知道没有使用的代码.

I'm attempting to set up proguard for my Android project. We use some pieces of a netty library in our code and I'd like to use Proguard to completely remove the pieces of code that I know aren't used.

有什么方法可以告诉 proguard 假设包(或类)从未使用过,因此不应包含在输出 JAR 中?请注意,我不是谈论从混淆中排除某些代码(这是 -keep 配置选项所做的),我谈论的是完全删除 输出中的一个类.

Is there some way to tell proguard to assume a package (or class) is never used and so should not be included in the output JARs? Note that I'm not talking about excluding some code from obfuscation (which is what the -keep configuration options do), I'm talking about completely removing a class from the output.

编辑:正如下面的 pst 所建议的,我尝试使用 -whyareyoukeeping 参数来确定 proguard 用于确定使用类的代码路径.它不会改变几十个警告的输出.

Edit: As suggested by pst below, I tried to use the -whyareyoukeeping argument to determine the code path that proguard uses to determine a class is used. It does not change the output of dozens of warnings.

我还尝试按照 pst 的建议在 -outjars 上使用文件过滤器.这也导致没有变化,因为算法仍然假设类将被加载,并且过滤器仅在使用的"类被错误确定后才应用.

I also attempted to use a file filter on -outjars as suggested by pst. This also resulted in no change as the algorithm still assumes the class will be loaded and the filter is only applied after the "used" classes are determined incorrectly.

需要明确的是:警告来自我们在 Android 项目中包含的 3rd 方库中的类.我们不执行任何会加载这些类的代码,如果 proguard 找到了一个代码路径,它确实假设加载了这些类,我想明确地说它使用这些类.

To be clear: the warnings are coming from classes in 3rd party libraries that we are including in our Android project. We don't execute any code that will load these classes, and if proguard finds a code path where it does assume these classes are loaded, I would like to explicitly say that it does not use those classes.

推荐答案

在 outjars 上指定过滤器的替代方法可能是在 injars 上指定过滤器:

An alternative to specifying a filter on the outjars could be to specify a filter on the injars:

-injars in.jar(!unwanted/package/**)

这样,您就不会不必要地拖入此包引用的任何类,因为过滤是在任何处理之前进行的.

This way, you won't unnecessarily drag in any classes that are referenced by this package, since the filtering is happening before any processing.

ProGuard 现在会警告丢失的类,所以你必须指定它没问题:

ProGuard will now warn about the missing classes, so you have to specify that it's ok:

-dontwarn unwanted.package.**

您应该小心使用这些选项,因为抑制警告并不一定会使问题消失.正如 pst 所写,如果您过滤掉实际需要的类,您将得到 NoClassDefFoundsErrors.

You should be careful with these options, since suppressing warnings does not necessarily make the problems go away. As pst wrote, you'll get NoClassDefFoundsErrors if you filter out classes that are actually required.

这篇关于我如何告诉 proguard 假设一个包没有被使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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