JAXB和StAX:处理“javax / xml / XMLConstants.class”时遇到问题

时间:2017-03-12 14:36:46

标签: android android-studio jaxb

我在一个项目中使用stax-apijaxb-api。课程javax.xml.XMLConstants有问题。我想这是因为两个依赖项都包含这个类。我对吗?还是有另一个问题?我可以在不启用multiDex的情况下解决这个问题吗(它不能正常工作。)

我正在使用AndroidStudio。因为我添加了stax-api

,就会出现问题

build.gradle(App):

android {
    compileSdkVersion 23
    buildToolsVersion '25.0.0'
    // ...
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 23
        // ...
    }
}
dependencies {
    compile 'javax.xml.stream:stax-api:1.0'
    compile 'javax.xml.bind:jaxb-api:2.2.12'
    // ...
}

Gradle Make输出:

Information:Gradle: Executing tasks: [:app:assembleDebug, :app:libraries:swagger-android-client:assembleDebug]
Information:Module "app" was fully rebuilt due to project configuration/dependencies changes
Information:12.03.2017 15:09 - Compilation completed with 34 errors and 0 warnings in 30s 984ms
Error:Gradle: trouble processing "javax/xml/XMLConstants.class":
Error:Gradle: Ill-advised or mistaken usage of a core class (java.* or javax.*)
Error:Gradle: when not building a core library.
Error:Gradle: This is often due to inadvertently including a core library file
Error:Gradle: in your application's project, when using an IDE (such as
Error:Gradle: Eclipse). If you are sure you're not intentionally defining a
Error:Gradle: core class, then this is the most likely explanation of what's
Error:Gradle: going on.
Error:Gradle: However, you might actually be trying to define a class in a core
Error:Gradle: namespace, the source of which you may have taken, for example,
Error:Gradle: from a non-Android virtual machine project. This will most
Error:Gradle: assuredly not work. At a minimum, it jeopardizes the
Error:Gradle: compatibility of your app with future versions of the platform.
Error:Gradle: It is also often of questionable legality.
Error:Gradle: If you really intend to build a core library -- which is only
Error:Gradle: appropriate as part of creating a full virtual machine
Error:Gradle: distribution, as opposed to compiling an application -- then use
Error:Gradle: the "--core-library" option to suppress this error message.
Error:Gradle: If you go ahead and use "--core-library" but are in fact
Error:Gradle: building an application, then be forewarned that your application
Error:Gradle: will still fail to build or run, at some point. Please be
Error:Gradle: prepared for angry customers who find, for example, that your
Error:Gradle: application ceases to function once they upgrade their operating
Error:Gradle: system. You will be to blame for this problem.
Error:Gradle: If you are legitimately using some code that happens to be in a
Error:Gradle: core package, then the easiest safe alternative you have is to
Error:Gradle: repackage that code. That is, move the classes in question into
Error:Gradle: your own package namespace. This means that they will never be in
Error:Gradle: conflict with core system classes. JarJar is a tool that may help
Error:Gradle: you in this endeavor. If you find that you cannot do this, then
Error:Gradle: that is an indication that the path you are on will ultimately
Error:Gradle: lead to pain, suffering, grief, and lamentation.
Error:Gradle: 1 error; aborting
Error:Gradle: Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: Unable to pre-dex 'C:\Users\armin\.gradle\caches\modules-2\files-2.1\javax.xml.stream\stax-api\1.0\a5be00d58ecaf5b01037b149f70e93ebcfb18fd1\stax-api-1.0.jar' to 'C:\Users\armin\StudioProjects\MyApp\app\build\intermediates\pre-dexed\debug\stax-api-1.0_5ef65f1cf66782d491b19b4710e1f54e44751b15.jar'

1 个答案:

答案 0 :(得分:1)

问题是 javax.xml.stream:stax-api:1.0 包含 javax.xml.XMLConstants ,但包含包" javax.xml的类。 "被JDK禁止。 使用 javax.xml.stream:stax-api:1.0.2 ,这应该可以解决JAR中已删除的 javax.xml.XMLConstants 的原因。 您可以在https://mvnrepository.com/artifact/javax.xml.stream

中找到详细信息