如何在Android Studio中清除Gradle依赖项?

时间:2014-10-27 13:37:34

标签: android gradle android-studio

我已将依赖项添加到Gradle,之后我无法构建我的应用程序。即使我清理Gradle缓存,我也无法进行构建。我在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":

如何清除Gradle以避免此错误?

更新

我的构建文件

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

添加

dexOptions {
    preDexLibraries = false
}

我收到了

    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)

2 个答案:

答案 0 :(得分:0)

尝试在android{}块中添加以下代码:

        dexOptions {
            preDexLibraries = false
        }

答案 1 :(得分:-2)

您要包含一个非Android设计的库。

以下几行是关于Restlet,Java EE版本。

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')

阅读本文档可能对您有所帮助:

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

您必须为Restlet设置自定义存储库,然后要求使用Android版而不是Java EE版。

首先,将其更改为您的Gradle文件:

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

然后,更改这些依赖项:

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') 

修改

你在评论中说这不能解决问题。我找到了有关此问题的更多信息:Android Studio ignore --core-library flag

您应该将其添加到您的Gradle文件中:

dexOptions {
    coreLibrary = true;
}