Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Htmlunit on Android application

Has anybody gotten HTMLUnit (or HtmlUnitDriver) to work on Android apps?

This is the problem: I am getting the following error message:

11-26 16:27:26.617: E/AndroidRuntime(1265): java.lang.NoClassDefFoundError: org/w3c/dom/css/CSSRule

This is what I did: I tried adding adding references to the jars listed in the following link (under both Project Dependencies and Project Transitive Dependencies - compile only, excluding test jars):

http://htmlunit.sourceforge.net/dependencies.html

However Eclipse kept crashing, then I found a few questions saying some jars are already contained in the Android SDK:

xalan, xercesImpl and xml-apis

HtmlUnit on Android

HttpClient

Android Programming HtmlUnit

So I removed the references to these jars keeping only the following:

commons-codec-1.4.jar
commons-collections-3.2.1.jar
commons-io-2.0.1.jar
commons-lang-2.6.jar
commons-logging-1.1.1.jar
cssparser-0.9.5.jar
htmlunit-2.9.jar
htmlunit-core-js-2.9.jar
httpmime-4.1.2.jar
nekohtml-1.9.15.jar
sac-1.3.jar
httpcore-4.1.3.jar

It was at this point when the app was able to run but when the following line of code was executed I started to get the error:

final WebClient webClient = new WebClient();

11-26 16:27:26.617: E/AndroidRuntime(1265): java.lang.NoClassDefFoundError: org/w3c/dom/css/CSSRule

I did a web search and found that xml-apis-1.3.04.jar contains org/w3c/dom/css/CSSRule so I put that reference back to the project but the app wouldn't build at all saying the same error message described in the first link above:

[2011-11-26 16:39:52 - Myproj] Conversion to Dalvik format failed with error 1

Could somebody please shed some light on this?

like image 640
Ulises Avatar asked Nov 26 '11 22:11

Ulises


1 Answers

xml-apis-1.3.04.jar contains core classes. You have to modify the jar and delete those classes.

Please note that, at least in current ADT version, you are getting a message explaining the problem:

Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.
like image 183
Juan Sánchez Avatar answered Sep 21 '22 03:09

Juan Sánchez