0

故事是这样的:我需要为一个 Android 库配置 Proguard,其中包含一个带有 JMDNS 库的 .jar 文件。我知道代码可以完美运行。

当我启用 proward 并尝试构建库时,控制台上会打印以下错误

Warning:javax.jmdns.impl.DNSCache: can't find referenced method 'java.util.concurrent.ConcurrentHashMap$KeySetView keySet()' in program class javax.jmdns.impl.DNSCache
Warning:javax.jmdns.impl.DNSCache: can't find referenced class java.util.concurrent.ConcurrentHashMap$KeySetView
Warning:there were 2 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)
Warning:there were 1 unresolved references to program class members.
         Your input classes appear to be inconsistent.
         You may need to recompile the code.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)

读了一下,我发现标签-dontwarn可以用来忽略这种类型的警告。应用后,控制台显示此警告

Warning:javax.jmdns.impl.DNSCache: can't find referenced method 'java.util.concurrent.ConcurrentHashMap$KeySetView keySet()' in program class javax.jmdns.impl.DNSCache
Warning:there were 1 unresolved references to program class members.
         Your input classes appear to be inconsistent.
         You may need to recompile the code.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)

有没有办法摆脱该消息,以便编译过程可以继续?我试图-dontwarn用失败的方法添加另一个,甚至-ignorewarnings没有成功的标签。

顺便说一下,我的 proguard-rules.pro:

-keep class com.google.common.io.Resources {
    public static <methods>;
}
-keep class com.google.common.collect.Lists {
    public static ** reverse(**);
}
-keep class com.google.common.base.Charsets {
    public static <fields>;
}

-keep class com.google.common.base.Joiner {
    public static Joiner on(String);
    public ** join(...);
}

-keep class com.google.common.collect.MapMakerInternalMap$ReferenceEntry
-keep class com.google.common.cache.LocalCache$ReferenceEntry
-keep class java.util.concurrent.ConcurrentHashMap$KeySetView

-dontwarn sun.misc.Unsafe
-dontwarn java.util.concurrent.ConcurrentHashMap$KeySetView

提前致谢

4

1 回答 1

0

我自己解决了它,并将回答我自己的问题,以便解决方案可以帮助其他人

警告基本上指出了解决方案:

Your input classes appear to be inconsistent.
You may need to recompile the code.

起初我以为是我的代码需要重新编译,但实际上是 JMDNS 代码有问题。下载源代码自己编译后没有出现问题

于 2015-09-04T16:21:29.627 回答