使用带有 proguard 关闭力的 jsoup 关闭

Posted

技术标签:

【中文标题】使用带有 proguard 关闭力的 jsoup 关闭【英文标题】:using jsoup with proguard closing force close 【发布时间】:2012-12-29 21:19:53 【问题描述】:

编辑:我的 PROGUARD 版本是 4.7

今天我尝试在我的android应用程序中包含jsoup (version 1.7.1),但这给我带来了很多麻烦。当我导出签名的apkproguard 打开 每次我的应用程序面临强制关闭问题时,我禁用了proguard 并导出了apk,它运行完美。请帮我。我该如何解决这个错误?堆栈跟踪如下:

java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:278)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:107
6)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:56
9)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.ExceptionInInitializerError
at org.jsoup.nodes.Document$OutputSettings.<init>(Unknown Source)
at org.jsoup.nodes.Document.<init>(Unknown Source)
at org.jsoup.parser.TreeBuilder.void initialiseParse(java.lang.String,java.lang.
String,org.jsoup.parser.ParseErrorList)(Unknown Source)
at org.jsoup.parser.TreeBuilder.org.jsoup.nodes.Document parse(java.lang.String,
java.lang.String,org.jsoup.parser.ParseErrorList)(Unknown Source)
                            boolean process(org.jsoup.parser.Token)
at org.jsoup.parser.htmlTreeBuilder.org.jsoup.nodes.Document parse(java.lang.Str
ing,java.lang.String,org.jsoup.parser.ParseErrorList)(Unknown Source)
                                boolean process(org.jsoup.parser.Token)
                                boolean process(org.jsoup.parser.Token,org.j
soup.parser.HtmlTreeBuilderState)
                                void transition(org.jsoup.parser.HtmlTreeBui
lderState)
                                org.jsoup.parser.HtmlTreeBuilderState state(
)
                                void framesetOk(boolean)
                                void maybeSetBaseUri(org.jsoup.nodes.Element
)
                                org.jsoup.nodes.Element insert(org.jsoup.par
ser.Token$StartTag)
                                org.jsoup.nodes.Element insert(java.lang.Str
ing)
                                void insert(org.jsoup.parser.Token$Comment)
                                void insert(org.jsoup.parser.Token$Character
)
                                boolean isElementInQueue(org.jsoup.helper.De
scendableLinkedList,org.jsoup.nodes.Element)
                                void popStackToClose(java.lang.String[])
                                void insertOnStackAfter(org.jsoup.nodes.Elem
ent,org.jsoup.nodes.Element)
                                void replaceInQueue(java.util.LinkedList,org
.jsoup.nodes.Element,org.jsoup.nodes.Element)
                                boolean inSpecificScope(java.lang.String,jav
a.lang.String[],java.lang.String[])
                                boolean inSpecificScope(java.lang.String[],j
ava.lang.String[],java.lang.String[])
                                boolean inScope(java.lang.String,java.lang.S
tring[])
                                void insertInFosterParent(org.jsoup.nodes.No
de)
at org.jsoup.parser.Parser.org.jsoup.nodes.Document parse(java.lang.String,java.
lang.String)(Unknown Source)
at org.jsoup.Jsoup.org.jsoup.nodes.Document parse(java.lang.String)(Unknown Sour
ce)
at com.my.package.name.BalCheck.void doLogin(java.lang.String,java.lang
.String)(Unknown Source)
                                     void checkBal()
                                     void echo(java.lang.String)
at com.my.package.name.BalCheck.void doCheckBalance(java.lang.String,ja
va.lang.String)(Unknown Source)
at com.my.package.name.SmsPage$CheckUltooBalance.java.lang.Void doInBac
kground(java.lang.Void[])(Unknown Source)
                                                      void onPostExecute(jav
a.lang.Void)
at com.my.package.name.SmsPage$CheckUltooBalance.java.lang.Object doInB
ackground(java.lang.Object[])(Unknown Source)
at android.os.AsyncTask$2.call(AsyncTask.java:264)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
... 5 more
Caused by: java.lang.ExceptionInInitializerError
at org.jsoup.nodes.Entities$EscapeMode.<clinit>(Unknown Source)
... 18 more
Caused by: java.lang.NullPointerException
at java.util.Properties.load(Properties.java:246)
at org.jsoup.nodes.Entities.java.util.Map loadEntities(java.lang.String)(Unknown
 Source)
at org.jsoup.nodes.Entities.<clinit>(Unknown Source)
... 19 more

【问题讨论】:

【参考方案1】:

@Erdem 在上面的评论中发布的解决方案似乎是最好的解决方案。我将其转发为可见性的答案。

将下面的行添加到您的 proguard 文件中

-keeppackagenames org.jsoup.nodes

这似乎足够了

【讨论】:

谢谢 - @android-newbie 应该会接受它;-)【参考方案2】:

你可以去jsoup with proguard寻找答案,也就是在proguard-project.txt中添加以下内容:

-keep public class org.jsoup.** 
public *;

【讨论】:

无需保留所有内容。这就足够了:-keeppackagenames org.jsoup.nodes 救生员...:)【参考方案3】:

只需在 proguard-rules.txt 中添加这些行

#Jsoup
-keep public class org.jsoup.** 
public *;

-keeppackagenames org.jsoup.nodes

【讨论】:

以上是关于使用带有 proguard 关闭力的 jsoup 关闭的主要内容,如果未能解决你的问题,请参考以下文章

使用属性打开/关闭 Proguard

JSoup 解析带有未闭合标签的无效 HTML

带有 ProGuard 的 Firebase

关闭 Jsoup 连接

还有比Jsoup更快的HTML搜刮吗?[关闭]

使用带有 Firebase 身份验证的 ProGuard 构建 Flutter 崩溃