java Android ProGuard:找不到引用的类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33048819/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 21:07:20  来源:igfitidea点击:

Android ProGuard: can't find referenced class

javaandroidandroid-studioproguardandroid-proguard

提问by confile

Running ProGuard in my Android Studio Project I get warnings like this:

在我的 Android Studio 项目中运行 ProGuard 我收到如下警告:

Warning: com.google.common.collect.Maps: can't find referenced class javax.annotation.Nullable

I might solve this with one of this variants:

我可能会用以下变体之一解决这个问题:

1

1

-keep class com.google.common.collect.** { *; }
-dontwarn com.google.common.collect.**

2

2

-keep class javax.annotation.** { *; }
-dontwarn javax.annotation.**

What is the best way to solve the above warning? What is the difference between variant 1. and 2.?

解决上述警告的最佳方法是什么?变体 1. 和 2. 之间有什么区别?

回答by Sankalp Pandya

This is the most common error beacuse of "many pre-compiled third-party libraries refer to other libraries that are not actually used and therefore not present. This works fine in debug builds, but in release builds, ProGuard expects all libraries, so it can perform a proper static analysis."

这是最常见的错误,因为“许多预编译的第三方库引用了其他未实际使用的库,因此不存在。这在调试版本中工作正常,但在发布版本中,ProGuard 需要所有库,因此它可以进行适当的静态分析。”

From: http://proguard.sourceforge.net/index.html#manual/examples.html

来自:http: //proguard.sourceforge.net/index.html#manual/examples.html

So,this javax.annotation.Nullablemight not be there in your project but the libraries you are using has some classes who are internally referring to them.

因此,这javax.annotation.Nullable可能不在您的项目中,但是您正在使用的库有一些在内部引用它们的类。

However you can avoid these warnings by -dontwarn javax.annotation.**or --dontwarn com.google.common.collect.**. But I dont think -keep class javax.annotation.** { *; }and looks illogical.

但是,您可以通过-dontwarn javax.annotation.**或来避免这些警告--dontwarn com.google.common.collect.**。但我不认为-keep class javax.annotation.** { *; }和看起来不合逻辑。

So, if you do -keep class com.google.common.collect.** { *; }you skip this package from all 3 steps of Proguardexecution (Shrinking,optimization and obfuscation) which makes sense according to my understanding.

所以,如果你这样做,你会-keep class com.google.common.collect.** { *; }从所有 3 个Proguard执行步骤(收缩、优化和混淆)中跳过这个包,根据我的理解这是有道理的。

回答by Gopi Cg

Don't forget to add package

不要忘记添加包

-keep class com.package_name.** { *; }

回答by Frank

Use the support libs Nullable instead:

使用支持库 Nullable 代替:

import android.support.annotation.Nullable;