如何找出 ProGuard Android 无法解析的 类

How to find out which classes cannot be resolved by ProGuard Android

为我正在使用的所有库添加 ProGuard 规则后,我仍然收到此警告:

Warning: there were 14 unresolved references to classes or interfaces.
         You may need to add missing library jars or update their versions.
         If your code works fine without the missing classes, you can suppress
         the warnings with '-dontwarn' options.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)

我知道我可能可以使用 -dontwarn 选项来摆脱这个警告,但因此我需要知道哪个 packages/classes/interfaces 无法解决。 Android 不支持全局“-dontwarn”。

在日志文件中我发现了很多注释和警告,但其中 none 似乎与上述消息有关。

如果您收到 Warning: there were X unresolved references to classes or interfaces,则在构建日志中查找包含单词 Warning 的行,例如:

Warning: com.package.Class1: can't find referenced class org.library.Class2

像这样的行将说明 ProGuard 正在尝试处理哪些 classes 以及在输入 jars 中找不到哪些 classes。在上面的示例中,class Class1 将引用库的 Class2,但在构建路径中找不到 Class2

正如您提到的,您可以简单地添加 -dontwarn <class regex> 来忽略这些警告,但理想情况下您应该检查它们 one-by-one 以确保您的配置正确并且所有必需的依赖项都被正确导入。