android – using jsoup with proguard closing force close-ThrowExceptions

Exception or error:

EDIT : MY PROGUARD VERSION IS 4.7

Today I tried include jsoup (version 1.7.1) in my android application, but it is causing me a lot of troubles. When I exported the signed apk with proguard turned on everytime my application was facing force close issues, then i disabled proguard and exported the apk and it ran perfectly. Please help me. How can I solve the error? The stacktrace is as below:

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
How to solve:

The solution posted by @Erdem in a comment above seems to be the best one. I’m reposting it as an answer for visibility.

Add the line below to your proguard file

-keeppackagenames org.jsoup.nodes

This seems to be enough

###

You can go to jsoup with proguard to find answer, which is to add the following to proguard-project.txt:

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

###

Just add these lines in proguard-rules.txt

#Jsoup
-keep public class org.jsoup.** {
public *;
}
-keeppackagenames org.jsoup.nodes

Leave a Reply

Your email address will not be published. Required fields are marked *