Android 应用程序上的 Htmlunit
有人让 HTMLUnit(或 HtmlUnitDriver)在 Android 应用程序上工作吗?
这就是问题:我收到以下错误消息:
11-26 16:27:26.617: E/AndroidRuntime(1265): java.lang.NoClassDefFoundError: org/w3c/dom/css/CSSRule
这就是我所做的:我尝试添加对以下链接中列出的 jar 的引用(在两个项目下)依赖项和项目传递依赖项 - 仅编译,不包括测试 jar):
http://htmlunit.sourceforge.net/dependency.html
但是 Eclipse 一直崩溃,然后我发现了一些问题,说一些 jars 已经包含在 Android SDK 中:
xalan, xercesImpl and xml-apis
HttpClient
因此,我删除了对这些 jar 的引用,只保留以下内容
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
:能够运行,但是当执行以下代码行时,我开始收到错误:
final WebClient webClient = new WebClient();
11-26 16:27:26.617: E/AndroidRuntime(1265): java.lang.NoClassDefFoundError: org/w3c/dom/css/CSSRule
我进行了网络搜索,发现 xml-apis-1.3.04.jar 包含org/w3c/dom/css/CSSRule 所以我将该引用放回到项目中,但应用程序根本无法构建,并显示上面第一个链接中描述的相同错误消息:
[2011-11-26 16:39:52 - Myproj] Conversion to Dalvik format failed with error 1
有人可以摆脱吗对此有一些了解吗?
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
HttpClient
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
xml-apis-1.3.04.jar 包含核心类。您必须修改 jar 并删除这些类。
请注意,至少在当前的 ADT 版本中,您会收到一条解释问题的消息:
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:
正如 ULsies 在评论中所述 Htmlunit 这样做 ==> HtmlUnit 是“Java 程序的无 GUI 浏览器”。它对 HTML 文档进行建模并提供一个 API,允许您调用页面、填写表单、单击链接等......就像您在“普通”浏览器中所做的那样。
在您的活动中打开网页
这与 android sdk 内提供的 webview 小部件完全相同,您不需要任何其他额外的 jar 即可根据 google android 文档
WebView 是显示网页的视图。它使用 WebKit 渲染引擎来显示网页,并包含在历史记录中向前和向后导航、放大和缩小、执行文本搜索等的方法。
将其添加到您的活动布局 xml 文件中。
并将其添加到您的活动类文件中。
更多信息请参见:http://developer.android .com/guide/webapps/webview.html
Just as ULsies stated in the comments Htmlunit does this ==> HtmlUnit is a "GUI-Less browser for Java programs". It models HTML documents and provides an API that allows you to invoke pages, fill out forms, click links, etc... just like you do in your "normal" browser.
which is exactly similar to webview widget provided inside the android sdk you dont need any other extra jar to open a web page inside your activity
as per google android documentation
A WebView is a View that displays web pages.It uses the WebKit rendering engine to display web pages and includes methods to navigate forward and backward through a history, zoom in and out, perform text searches and more.
add this to your activity layout xml file.
and this to your activity class file..
more on this here: http://developer.android.com/guide/webapps/webview.html