我有一个实现 Compartor 的类,它重写了比较函数:
import java.util.Comparator;
public class ScoreComparator implements Comparator<Score>
{
@Override
public int compare(Score s1, Score s2)
{
return Integer.compare(s2.score, s1.score);
}
}
当我使用 proguard 进行编译时,出现以下错误:
can't find referenced method 'int compare(int,int)' in class java.lang.Integer You should check if you need to specify additional program jars. there were 1 unresolved references to program class members. Your input classes appear to be inconsistent. You may need to recompile them and try again. Alternatively, you may have to specify the option '-dontskipnonpubliclibraryclassmembers'.
所以我显然添加了该选项。但是,我遇到了同样的错误。
那么应该在 proguard 配置中添加哪些额外选项来消除此错误?
最佳答案
您的代码使用的是 Integer#compare(int,int),它仅在 JDK 1.7 中存在。因此,您还应该确保为 ProGuard 指定的 Java 运行时 jar 是 JDK 1.7 中的 jar。
注意:您似乎将 Java 运行时 jar 指定为程序 jar (-injars)。您可能希望将其指定为库 jar (-libraryjars),因此它最终不会成为您的应用程序的一部分。
关于Java Proguard 和 int 比较器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17488869/