Wednesday, July 22, 2015

Android Studio: Ill-advised or mistaken usage of a core class (java.* or javax.*)

Adding xmlrpc-client library to the application
                               compile 'org.apache.xmlrpc:xmlrpc-client:3.1.3'
causes the following error during run:
trouble processing "javax/xml/parsers/DocumentBuilder.class":
Ill-advised or mistaken usage of a core class (java.* or javax.*)


DocumentBuilder is already included in android. So we should exclude xml-apis in gradle:

compile ('org.apache.xmlrpc:xmlrpc-client:3.1.3') {
    exclude group: 'xml-apis'
}






But after that I’ve got the next errors:
Error:Execution failed for task ':app:packageDebug'.
> Duplicate files copied in APK META-INF/DEPENDENCIES
    File 1: C:\Users\jm\.gradle\caches\modules-2\files-2.1\org.apache.xmlrpc\xmlrpc-client\3.1.3\e486ad917028b52265610206fb5a1e2b5914b94b\xmlrpc-client-3.1.3.jar
    File 2: C:\Users\jm\.gradle\caches\modules-2\files-2.1\org.apache.xmlrpc\xmlrpc-common\3.1.3\415daf1f1473a947452588906dc9f5b3575fb44d\xmlrpc-common-3.1.3.jar
Information:BUILD FAILED
You can ignore those files in your build.gradle:
    android {
      packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
      }
    }

 
In this case there are at least two ways to fix:
1.       Use exclude in packagingOptions:
packagingOptions {
     exclude 'META-INF/DEPENDENCIES'
     exclude 'META-INF/LICENSE'
     exclude 'META-INF/NOTICE'
 }

2.       Use pickFirst option:
packagingOptions {
    pickFirst 'META-INF/DEPENDENCIES'
    pickFirst 'META-INF/LICENSE'
    pickFirst 'META-INF/NOTICE'
}


No comments:

Post a Comment