4

I've added dependencies to Gradle and after that I can't build my application. Even if I clean Gradle cache I can't make my build. I receive this error message on Android:

trouble processing "javax/xml/stream/EventFilter.class":

Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.

This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most likely explanation of what's
going on.

However, you might actually be trying to define a class in a core
namespace, the source of which you may have taken, for example,
from a non-Android virtual machine project. This will most
assuredly not work. At a minimum, it jeopardizes the
compatibility of your app with future versions of the platform.
It is also often of questionable legality.

If you really intend to build a core library -- which is only
appropriate as part of creating a full virtual machine
distribution, as opposed to compiling an application -- then use
the "--core-library" option to suppress this error message.

If you go ahead and use "--core-library" but are in fact
building an application, then be forewarned that your application
will still fail to build or run, at some point. Please be
prepared for angry customers who find, for example, that your
application ceases to function once they upgrade their operating
system. You will be to blame for this problem.

If you are legitimately using some code that happens to be in a
core package, then the easiest safe alternative you have is to
repackage that code. That is, move the classes in question into
your own package namespace. This means that they will never be in
conflict with core system classes. JarJar is a tool that may help
you in this endeavor. If you find that you cannot do this, then
that is an indication that the path you are on will ultimately
lead to pain, suffering, grief, and lamentation.

1 error; aborting
:app:preDexDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preDexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /Applications/Android Studio.app/sdk/build-tools/21.0.2/dx --dex --output /Users/alex/AndroidStudioProjects/client-poc/app/build/intermediates/pre-dexed/debug/stax-api-1.0-2-423956290996cba5c5243bbc25620fb74a9a3abd.jar /Users/alex/.gradle/caches/modules-2/files-2.1/javax.xml.stream/stax-api/1.0-2/d6337b0de8b25e53e81b922352fbea9f9f57ba0b/stax-api-1.0-2.jar
  Error Code:
    1
  Output:

    trouble processing "javax/xml/stream/EventFilter.class":

How can I clean Gradle to avoid this error?

UPDATE

My build file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.0.2"

    defaultConfig {
        applicationId "com.soft.android_client"
        minSdkVersion 19
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    lintOptions {
        abortOnError false
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile ('org.restlet.jee:org.restlet:2.3-M3')
    compile ('org.restlet.jee:org.restlet.ext.jackson:2.3-M3')
    compile ('org.restlet.jee:org.restlet.ext.jaxb:2.3-M3')
    compile ('org.restlet.jee:org.restlet.ext.xml:2.3-M3')
}

UPDATE2

After adding

dexOptions {
    preDexLibraries = false
}

I received

    UNEXPECTED TOP-LEVEL ERROR:
java.lang.AssertionError: com.android.dx.command.dexer.Main$StopProcessing
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:542)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:279)
    at com.android.dx.command.dexer.Main.run(Main.java:245)
    at com.android.dx.command.dexer.Main.main(Main.java:214)
    at com.android.dx.command.Main.main(Main.java:106)
Error:com.android.dx.command.dexer.Main$StopProcessing
    at com.android.dx.command.dexer.Main.checkClassName(Main.java:785)
    at com.android.dx.command.dexer.Main.processClass(Main.java:697)
    at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
    at com.android.dx.command.dexer.Main.access$300(Main.java:82)
    at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
    at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
    at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
    at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
    at com.android.dx.command.dexer.Main$ParallelProcessor.call(Main.java:1600)
    at com.android.dx.command.dexer.Main$ParallelProcessor.call(Main.java:1590)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /Applications/Android Studio.app/sdk/build-tools/21.0.2/dx --dex --num-threads=4 --output /Users/alex/AndroidStudioProjects/client-poc/app/build/intermediates/dex/debug /Users/alex/AndroidStudioProjects/client-poc/app/build/intermediates/classes/debug /Users/alex/AndroidStudioProjects/client-poc/app/build/intermediates/dependency-cache/debug 

...

  Error Code:
    3
  Output:
    trouble processing "javax/xml/stream/EventFilter.class":
    Ill-advised or mistaken usage of a core class (java.* or javax.*)
    when not building a core library.
    This is often due to inadvertently including a core library file
    in your application's project, when using an IDE (such as
    Eclipse). If you are sure you're not intentionally defining a
    core class, then this is the most likely explanation of what's
    going on.
    However, you might actually be trying to define a class in a core
    namespace, the source of which you may have taken, for example,
    from a non-Android virtual machine project. This will most
    assuredly not work. At a minimum, it jeopardizes the
    compatibility of your app with future versions of the platform.
    It is also often of questionable legality.
    If you really intend to build a core library -- which is only
    appropriate as part of creating a full virtual machine
    distribution, as opposed to compiling an application -- then use
    the "--core-library" option to suppress this error message.
    If you go ahead and use "--core-library" but are in fact
    building an application, then be forewarned that your application
    will still fail to build or run, at some point. Please be
    prepared for angry customers who find, for example, that your
    application ceases to function once they upgrade their operating
    system. You will be to blame for this problem.
    If you are legitimately using some code that happens to be in a
    core package, then the easiest safe alternative you have is to
    repackage that code. That is, move the classes in question into
    your own package namespace. This means that they will never be in
    conflict with core system classes. JarJar is a tool that may help
    you in this endeavor. If you find that you cannot do this, then
    that is an indication that the path you are on will ultimately
    lead to pain, suffering, grief, and lamentation.
    trouble processing "javax/xml/bind/Binder.class":
    Ill-advised or mistaken usage of a core class (java.* or javax.*)
    when not building a core library.
    This is often due to inadvertently including a core library file
    in your application's project, when using an IDE (such as
    Eclipse). If you are sure you're not intentionally defining a
    core class, then this is the most likely explanation of what's
    going on.
    However, you might actually be trying to define a class in a core
    namespace, the source of which you may have taken, for example,
    from a non-Android virtual machine project. This will most
    assuredly not work. At a minimum, it jeopardizes the
    compatibility of your app with future versions of the platform.
    It is also often of questionable legality.
    If you really intend to build a core library -- which is only
    appropriate as part of creating a full virtual machine
    distribution, as opposed to compiling an application -- then use
    the "--core-library" option to suppress this error message.
    If you go ahead and use "--core-library" but are in fact
    building an application, then be forewarned that your application
    will still fail to build or run, at some point. Please be
    prepared for angry customers who find, for example, that your
    application ceases to function once they upgrade their operating
    system. You will be to blame for this problem.
    If you are legitimately using some code that happens to be in a
    core package, then the easiest safe alternative you have is to
    repackage that code. That is, move the classes in question into
    your own package namespace. This means that they will never be in
    conflict with core system classes. JarJar is a tool that may help
    you in this endeavor. If you find that you cannot do this, then
    that is an indication that the path you are on will ultimately
    lead to pain, suffering, grief, and lamentation.
    warning: Ignoring InnerClasses attribute for an anonymous inner class
    (javax.activation.DataHandler$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.
    warning: Ignoring InnerClasses attribute for an anonymous inner class
    (javax.activation.SecuritySupport$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.
    warning: Ignoring InnerClasses attribute for an anonymous inner class
    (javax.activation.SecuritySupport$2) 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.
    warning: Ignoring InnerClasses attribute for an anonymous inner class
    (javax.activation.SecuritySupport$3) 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.
    warning: Ignoring InnerClasses attribute for an anonymous inner class
    (javax.activation.SecuritySupport$4) 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.
    warning: Ignoring InnerClasses attribute for an anonymous inner class
    (javax.activation.SecuritySupport$5) 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.
    UNEXPECTED TOP-LEVEL ERROR:
    java.lang.AssertionError: com.android.dx.command.dexer.Main$StopProcessing
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:542)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:279)
        at com.android.dx.command.dexer.Main.run(Main.java:245)
        at com.android.dx.command.dexer.Main.main(Main.java:214)
        at com.android.dx.command.Main.main(Main.java:106)
    Caused by: com.android.dx.command.dexer.Main$StopProcessing
        at com.android.dx.command.dexer.Main.checkClassName(Main.java:785)
        at com.android.dx.command.dexer.Main.processClass(Main.java:697)
        at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
        at com.android.dx.command.dexer.Main.access$300(Main.java:82)
        at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
        at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
        at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
        at com.android.dx.command.dexer.Main$ParallelProcessor.call(Main.java:1600)
        at com.android.dx.command.dexer.Main$ParallelProcessor.call(Main.java:1590)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Alex
  • 2,091
  • 6
  • 31
  • 49

2 Answers2

0

Try adding the following code inside the android{} block :

        dexOptions {
            preDexLibraries = false
        }
vkm
  • 548
  • 7
  • 23
-2

You are including a library that is not designed for Android.

The following lines are about Restlet, Java EE edition.

compile ('org.restlet.jee:org.restlet:2.3-M3')
compile ('org.restlet.jee:org.restlet.ext.jackson:2.3-M3')
compile ('org.restlet.jee:org.restlet.ext.jaxb:2.3-M3')
compile ('org.restlet.jee:org.restlet.ext.xml:2.3-M3')

Reading this documentation may help you :

http://restlet.com/download/current#release=stable&edition=android&distribution=maven

You will have to set a custom repository for Restlet, then asking for Android edition instead of Java EE edition.

Firstly, change this to your Gradle file :

repositories {
    mavenCentral()
    maven { url "http://maven.restlet.com" }
}

Then, change your dependencies for these ones :

compile ('org.restlet.android:org.restlet:2.3-M3')
compile ('org.restlet.android:org.restlet.ext.jackson:2.3-M3')
compile ('org.restlet.android:org.restlet.ext.jaxb:2.3-M3')
compile ('org.restlet.android:org.restlet.ext.xml:2.3-M3') 

EDIT

You said in comments that this do not resolve the issue. I found more information on this question : Android Studio ignore --core-library flag

You should add this to your Gradle file :

dexOptions {
    coreLibrary = true;
}
Community
  • 1
  • 1
mithrop
  • 3,283
  • 2
  • 21
  • 40
  • In fact if I add `org.restlet.android:org.*` libs I get the same error. – Alex Oct 27 '14 at 16:43
  • I do not have any other clue. I am sorry :( – mithrop Oct 27 '14 at 16:44
  • Find another hint actually... :) – mithrop Oct 27 '14 at 17:03
  • 1
    The error message says pretty sternly that you shouldn't use the ignore-core-library flag unless you really know what you're doing. – Scott Barta Oct 27 '14 at 17:21
  • I think that the library `org.restlet.ext.xml` or `org.restlet.ext.jaxb` should add some classes like `javax.xml.stream.EventFilter`. You can ensure it by checking the content of your four Restlet libraries – mithrop Oct 27 '14 at 17:35
  • It's weird because libraries for Android (http://maven.restlet.com/org/restlet/android/org.restlet.ext.jackson/2.3-M3/) cause to crash: `trouble processing "javax/xml/stream/EventFilter.class":` – Alex Oct 27 '14 at 17:57
  • `org.restlet.android:org.restlet.ext.jackson` include `javax.xml.stream:stax-api:1.0-2` – Alex Oct 27 '14 at 18:01
  • So here is your problem ;) If you include classes in the native namespace, you will continue to have this problem. – mithrop Oct 27 '14 at 19:34