我正在使用android上的jackson-dataformat-xml
我有一些非常基本的代码,可以在oracle jre上正常工作
JacksonXmlModule module = new JacksonXmlModule();
module.setDefaultUseWrapper(false);
XmlMapper xmlMapper = new XmlMapper(module);
首先我尝试official documentation改编为gradle(由我,不确定是否正确完成):
compile 'com.fasterxml.jackson.core:jackson-core:2.5.4'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.5.4'
compile 'com.fasterxml.jackson.core:jackson-databind:2.5.4'
compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.5.4'
compile 'org.codehaus.woodstox:woodstox-core-asl:4.4.1'
compile 'javax.xml.stream:stax-api:1.0-2'
结果:gradle将关于将corelibraries捆绑到应用程序中的构建时间失败
...
:app:preDexDebug
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.
...
试图追随肖恩answer的第二次尝试
(基本上他用前缀名称重新打包corelib并重建jackson-dataformat-xml以使用前缀名称)
compile 'com.fasterxml.jackson.core:jackson-core:2.1.2'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.1.2'
compile 'com.fasterxml.jackson.core:jackson-databind:2.1.2'
// Repackaged XML-specific libraries
compile 'edu.usf.cutr.android.xml:jackson-dataformat-xml-android:2.1.2'
compile 'edu.usf.cutr.android.xml:stax2-api-android:3.1.1'
compile 'edu.usf.cutr.android.xml:stax-api-android:1.0-2'
compile 'edu.usf.cutr.android.xml:aalto-xml-android:0.9.8'
复制时构建时间失败
Duplicate files copied in APK META-INF/services/com.fasterxml.jackson.core.ObjectCodec
添加:
packagingOptions {
...
exclude 'META-INF/services/com.fasterxml.jackson.core.JsonFactory'
exclude 'META-INF/services/com.fasterxml.jackson.core.ObjectCodec'
}
当添加它构建和部署的排除项时,但是在下面的stackdump上运行时失败(AFAIK它找不到SAX提供程序,即使它被添加到我的理解的类路径中)
edu.usf.cutr.javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.MXParserFactory not found
at edu.usf.cutr.javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.java:72)
at edu.usf.cutr.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:176)
at edu.usf.cutr.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:92)
at edu.usf.cutr.javax.xml.stream.XMLInputFactory.newInstance(XMLInputFactory.java:136)
at com.fasterxml.jackson.dataformat.xml.XmlFactory.(XmlFactory.java:97)
at com.fasterxml.jackson.dataformat.xml.XmlFactory.(XmlFactory.java:85)
at com.fasterxml.jackson.dataformat.xml.XmlFactory.(XmlFactory.java:82)
at com.fasterxml.jackson.dataformat.xml.XmlMapper.(XmlMapper.java:46)
在#1或#2上前进的正确方法是什么?