0

I am trying to use HtmlUnit which lists xml-apis-1.4.01.jar as a dependency. Though whenever I include this file in the libs/ directory I get the following error:

Error: trouble processing "javax/xml/XMLConstants.class":
Error: Ill-advised or mistaken usage of a core class (java.* or javax.*)
...

Could anyone help me resolve this.

Thanks!

Steve Eynon
  • 4,979
  • 2
  • 30
  • 48
Arunabh Ghosh
  • 318
  • 3
  • 11
  • You can add full logcat of error – Mohammod Hossain Nov 24 '16 at 04:33
  • Edited the title in an attempt to make it clearer. It may be useful to include extra details, such as which version of `Java` & `HtmlUnit`, how you are running the code to get the error (via IDE or console), and exactly which `libs/` directory you place the jar in. – Steve Eynon Nov 25 '16 at 03:04

1 Answers1

0

First of all, don't put .jars into libs folder, as you will quickly run into dependency hell. Use gradle build system for that. In your app module build.gradle file declare such dependency:

compile ('net.sourceforge.htmlunit:htmlunit:2.23') {
    exclude module: 'commons-logging'
    exclude module: 'httpclient'
}

And everything will build correctly.

R. Zagórski
  • 20,020
  • 5
  • 65
  • 90
  • Thank you! I followed the above steps but now I am getting new errors - ` ':app:transformResourcesWithMergeJavaResForDebug'. > com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE File1: /home/darknight/.gradle/caches/modules-2/files-2.1/xerces/xercesImpl/2.11.0/9bb329db1cfc4e22462c9d6b43a8432f5850e92c/xercesImpl-2.11.0.jar File2: /home/darknight/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.5.2/22b4c53dd9b6761024258de8f9240c3dce6ea368/httpmime-4.5.2.jar` – Arunabh Ghosh Nov 21 '16 at 14:36
  • Check [this solution](http://stackoverflow.com/questions/20673625/android-gradle-plugin-0-7-0-duplicate-files-during-packaging-of-apk) or add another `exlude module: 'httpmime'` – R. Zagórski Nov 21 '16 at 14:56
  • Thanks! I followed that solution..and now I am stuck at another error - `Error:(106, 48) error: cannot access ElementTraversal class file for org.w3c.dom.ElementTraversal not found` Could you help me with this one? – Arunabh Ghosh Nov 21 '16 at 15:09
  • Firstly, look for the solution on [Google](http://google.com/) or [SO](http://stackoverflow.com/). This is the second problem you experienced that has been already solved: http://stackoverflow.com/questions/17515333/noclassdeffounderror-org-w3c-dom-elementtraversal – R. Zagórski Nov 21 '16 at 15:20