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?
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.
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.
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
and this to your activity class file..
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("http://www.your url .com");
more on this here: http://developer.android.com/guide/webapps/webview.html
来源:https://stackoverflow.com/questions/8282259/htmlunit-on-android-application