【问题标题】:How to clean Gradle dependencies in Android Studio?如何在 Android Studio 中清理 Gradle 依赖项?
【发布时间】:2014-10-27 13:37:34
【问题描述】:

我已将依赖项添加到 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')
}

更新2

添加后

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)

【问题讨论】:

  • 您可以发布您的 Gradle 文件以确保并了解您的项目结构吗?你试过“gradle clean”吗?
  • 我更新了我的问题。
  • 你试过gradle clean 吗?
  • 是的,没用。
  • 我看到您还添加了一些 jar 文件(包括 /libs 目录中的所有 jar)。你能告诉我们这些库是什么吗?

标签: android gradle android-studio


【解决方案1】:

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

        dexOptions {
            preDexLibraries = false
        }

【讨论】:

  • 我添加了dexOptions ,但我再次收到错误消息。见 UPDATE2。
【解决方案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') 

编辑

您在 cmets 中说这不能解决问题。我找到了关于这个问题的更多信息:Android Studio ignore --core-library flag

你应该把它添加到你的 Gradle 文件中:

dexOptions {
    coreLibrary = true;
}

【讨论】:

  • 事实上,如果我添加 org.restlet.android:org.* 库,我会得到同样的错误。
  • 我没有任何其他线索。对不起:(
  • 实际上找到另一个提示... :)
  • 错误消息非常严厉地指出,除非您真的知道自己在做什么,否则不应使用 ignore-core-library 标志。
  • 我认为库org.restlet.ext.xmlorg.restlet.ext.jaxb 应该添加一些像javax.xml.stream.EventFilter 这样的类。您可以通过检查您的四个 Restlet 库的内容来确保它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-25
  • 1970-01-01
  • 2021-02-10
  • 2014-04-03
  • 2015-09-16
  • 2015-10-14
相关资源
最近更新 更多