How to fix XmlMapper exception - java.lang.VerifyError: com.fasterxml.jackson?

How to fix XmlMapper exception - java.lang.VerifyError: com.fasterxml.jackson?

Android Studio 2.2.2
Compile SDK Android 7.1.1
Build Tools: 25.0.0
Gradle version: 2.14.1
Min SDK: 19
Target SDK: 25

我在尝试执行此操作时遇到 jackson-dataformat-xml-2.8.5.jar 问题:

 JacksonXmlModule module = new JacksonXmlModule();
 ObjectMapper xmlMapper = new XmlMapper(); //This line

抛出以下异常

E/AndroidRuntime: FATAL EXCEPTION: Thread-418
              Process: cb.myAppName, PID: 29744
              java.lang.VerifyError: com/fasterxml/jackson/dataformat/xml/XmlFactory
                  at com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:49)
                  at cb.myAppName.Core.GenerateReturnXMLFile(Core.java:863)
                  at cb.myAppName.RouteScreenActivity.run(RouteScreenActivity.java:305)
                  at java.lang.Thread.run(Thread.java:841)

根据我的研究,它与 Jackson 1.3 中引入的二进制不兼容有关。正如 Tatu Saloranta 在他的旧博客中所说的那样,遗憾的是它不再在线。

I have always valued compatibility quite highly, at least for any "non beta" release (1.0 and above). As a result, the idea has been that any 1.x release would be simple plug-and-play over previous one. This does work for patch releases; but it turns out that not all minor releases have worked this way. For example, versions 1.2 and 1.3 have some unexpected incompatibilities.

Problem is this: although most commonly binary compatibility is a harder goal than source compatibility -- that is, if you break source compatibility, you are almost guaranteed to break binary compatibility -- it is not strictly so. Specifically, it is quite possible to make certain changes that are source compatible, but that are NOT binary compatible.

Specific case in point is that of changing a method that returns nothing ("void method") into method that returns something does not break compilation. But it does actually break binary compatibility. UGH.

And this is exactly what happened when I decided that it would be nice to make ObjectMapper follow "fluent" pattern, to allow for chaining of configuration method calls. This would be nice, if it was not this "hidden" API change...

不太确定如何纠正这个问题,因为我是 android 开发的新手。

我已经确保全面使用相同版本的 Jackson,正如您在 app/build.gradle 的依赖项列表中看到的那样,还有什么我可能遗漏的吗?

dependencies {
    compile fileTree(include: ['*.jar'], exclude: ['com.symbol.emdk.jar'], dir: 'libs')
    compile files('../libs/json-20151123.jar')
    provided files('../libs/com.symbol.emdk.jar')
    compile files('../libs/slf4j-api-1.7.6.jar')
    compile files('../libs/logback-android-1.1.1-4.jar')
    compile files('../libs/sun.misc.BASE64Decoder.jar')
    compile files('../libs/ZSDK_ANDROID_API.jar')
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.android.support:support-v7:22.2.0'
    compile 'com.google.code.ksoap2-android:ksoap2-android:3.6.0'
    compile 'com.google.code.gson:gson:2.4'
    compile 'org.apache.directory.studio:org.apache.commons.io:2.4'
    compile 'org.joda:joda-money:0.11'
    compile 'org.apache.directory.studio:org.apache.commons.lang:2.6'
    compile 'com.google.android.gms:play-services-appindexing:9.8.0'
    compile 'org.greenrobot:eventbus:3.0.0'
    compile 'com.fasterxml.jackson.core:jackson-core:2.8.5'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.8.5'
    compile 'com.fasterxml.jackson.datatype:jackson-datatype-joda:2.8.5'
    compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.8.5'
    compile 'com.github.gcacace:signature-pad:1.2.0'
}

根据官方FasterXML Jackson github page,我使用的扩展程序应该被支持...

XML: supports XML; provides both streaming and databind implementations. Similar to JAXB' "code-first" mode (no support for "XML Schema first", but can use JAXB beans)

https://github.com/FasterXML/jackson-dataformat-xml

该项目的 github 页面上也报告了此问题,但未达成真正的解决方案。 -- github.com/FasterXML/jackson-dataformat-xml/issues/116

更新:我在以下依赖项上使用了jarjar

compile files('../libs/cb-joda-time-2.9.6.jar')
compile files('../libs/cb-joda-money-0.12.jar')
compile files('../libs/cb-jackson-dataformat-xml-2.8.5.jar')
compile files('../libs/cb-jackson-datatype-joda-2.8.5.jar')
compile files('../libs/cb-java-json-0.13.0.jar')
compile files('../libs/cb-json-20160212.jar')

还将每个依赖项以及我的 appcompatsupport api.

升级到最新版本

错误继续 -

java.lang.VerifyError: cb/com/fasterxml/jackson/dataformat/xml/XmlFactory
                      at cb.com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:49)

希望有人能对此有所启发,不确定是什么原因造成的...

经过一些研究和用户 aha 的提示后,我能够进一步确定如何更正此问题。我没有时间测试它,因为我最终选择了不同的路线并使用 SimpleXML 库来代替它,它非常适合我需要做的事情。

当我开始测试它时,我会用更多细节更新这个答案,但这里有一些尝试和纠正这个问题的方法:

  • 包括 Stax 作为依赖项:github.com/FasterXML/jackson-dataformat-xml#android-quirks
  • 执行gradle dependencies。 Gradle 然后将显示它用于编译和打包您的应用程序的实际依赖关系树。生成的依赖关系树可能与您声明的依赖关系不同,例如因为传递依赖。 -谢谢aha

这是 github 的原始问题:github.com/FasterXML/jackson-dataformat-xml/issues/116