Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
763 views
in Technique[技术] by (71.8m points)

java - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...