在尝试使用 ProGuard (4.9) 来混淆和优化桌面应用程序时,一切正常,直到我使用来自外部库(例如JSoup.connect("http://google.com/").get();
. 我会收到以下错误:
Exception in thread "Thread-2" java.lang.ExceptionInInitializerError
at org.jsoup.b.l.<clinit>(Unknown Source)
at org.jsoup.b.f.<init>(Unknown Source)
at org.jsoup.b.e.<init>(Unknown Source)
at org.jsoup.c.bh.b(Unknown Source)
at org.jsoup.c.bh.a(Unknown Source)
at org.jsoup.c.b.a(Unknown Source)
at org.jsoup.c.D.a(Unknown Source)
at org.jsoup.a.a.a(Unknown Source)
at org.jsoup.a.i.e(Unknown Source)
at org.jsoup.a.e.a(Unknown Source)
at package.a.a(Unknown Source)
at package.a.b(Unknown Source)
at package.w.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Unknown Source)
at java.util.Properties.load0(Unknown Source)
at java.util.Properties.load(Unknown Source)
at org.jsoup.b.k.d(Unknown Source)
at org.jsoup.b.k.<clinit>(Unknown Source)
... 14 more
我曾尝试寻找解决方案,但答案总是针对 android 应用程序。没有运气,我尝试了以下操作:
- 关掉
Use mixed-class names
- 添加到配置
-keep public enum * { public static **[] values(); public static ** valueOf(java.lang.String); }
最近,使用 ProGuard 5.2 完成了这个过程,并没有太大变化。这是解决问题的更新过程:
- 转到混淆选项卡。
- 转到底部
Keep additional class names and class member names
- 点击
Add...
右侧 转到
Extends/implements class
并输入与以下示例匹配的库,然后按Ok
。对每个库重复。- 对于JSoup:
org.jsoup.**
- 对于 Apache Commons Net:
org.apache.commons.net.**
- 对于 SwingX:
org.jdesktop.**
- 对于 GSON:
org.google.gson.**
- 对于JSoup:
转到信息选项卡。
- 关掉
Skip non-public library class members
- 打开
Ignore warnings about possibly erroneous input
- 过程!