Android 上的 Proguard 和 JMDNS 问题
Proguard and JMDNS issue on Android
事情是这样的:我需要为一个 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
提前致谢
我自己解决了,我会回答我自己的问题,以便解决方案可以帮助其他人
警告基本指出解决方法:
Your input classes appear to be inconsistent.
You may need to recompile the code.
起初我以为是我的代码需要重新编译,但实际上是 JMDNS 代码有问题。下载源码后自己编译,问题没有出现
事情是这样的:我需要为一个 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
提前致谢
我自己解决了,我会回答我自己的问题,以便解决方案可以帮助其他人
警告基本指出解决方法:
Your input classes appear to be inconsistent.
You may need to recompile the code.
起初我以为是我的代码需要重新编译,但实际上是 JMDNS 代码有问题。下载源码后自己编译,问题没有出现