Java – HtmlUnit on Android: Dependencies

HtmlUnit on Android: Dependencies… here is a solution to the problem.

HtmlUnit on Android: Dependencies

The code runs in a normal Java project, but if I try on Android, copying the library (.jar) dependencies, it won’t build:

warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.commons.collections.BeanMap$1) that doesn’t come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any “-target” type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is not an inner class.

It concludes:

6 warnings
1 error; aborting
/home/kp/android-sdk-linux/tools/ant/build.xml:818: The following error occurred while executing this line:
/home/kp/android-sdk-linux/tools/ant/build.xml:820: The following error occurred while executing this line:
/home/kp/android-sdk-linux/tools/ant/build.xml:832: The following error occurred while executing this line:
/home/kp/android-sdk-linux/tools/ant/build.xml:278: null returned: 1

I added all libraries :

  • 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
  • httpclient-4.1.2.jar
  • httpcore-4.1.2.jar
  • httpmime-4.1.2.jar
  • nekohtml-1.9.15.jar
  • sac-1.3.jar
  • serializer-2.7.1.jar
  • xalan-2.7.1.jar
  • xercesImpl-2.9.1.jar
  • xml-apis-1.3.04.jar

If I remove some dependencies, it builds, but when it tries to execute my code _client = new WebClient(); I get a noClassDefFoundError error.

I haven’t found a solution yet, so if you have a solution, please share!

Solution

My guess is that your HTMLunit jar is not in the libs folder of the Android project.

You should create a libs folder (with exact spelling) at the root of your project and place all HTMLUnit jars under that folder.

Namely

Project/Library/

Related Problems and Solutions