Android ProGuard: Please correct the above warnings first


The ProGuard tool shrinks, optimizes, and obfuscates your code by removing unused code and renaming classes, fields, and methods with semantically obscure name.

Android SDK整合了ProGuard,并在文档中用了一个章节来描述如何使用它。依照文档来实施,多半没有问题,不过在我使用中遇到了一个问题:

[proguard] Warning: there were 2 unresolved references to classes or interfaces.
[proguard] You may need to specify additional library jars (using ‘-libraryjars’),
[proguard] or perhaps the ‘-dontskipnonpubliclibraryclasses’ option.
[proguard] Warning: there were 5 unresolved references to program class members.
[proguard] Your input classes appear to be inconsistent.
[proguard] You may need to recompile them and try again.
[proguard] Alternatively, you may have to specify the options
[proguard] ‘-dontskipnonpubliclibraryclasses’ and/or
[proguard] ‘-dontskipnonpubliclibraryclassmembers’.

/Users/xuhj/Develop/android-sdk-mac_x86/tools/ant/main_rules.xml:453: Please correct the above warnings first.

依照以往的惯例,发生warning,可忽视之,只有看到error,才会小紧张一把。不过这次的warning导致了BUILD FAILED,这回问题大了。


那就到官网找找答案吧,Manual -> Troubleshooting -> “Warning: can’t find referenced class”,找到这么一句话:try your luck with the -ignorewarnings option, or even the -dontwarn option.再对比日志信息,发现:

[proguard] Warning: net.poemcode.Digest: can’t find referenced class org.apache.CastleProvider

打开proguard.cfg,加入-dontwarn net.poemcode.**,再次执行ant release,万事大吉。

Leave a comment

Your comment