在 Android 中将 docx 转换为 html

Convert docx to html in Android

我想在 Android 中将 Word docx 文档(不是 doc)转换为 html。我尝试使用 Apache XWPF,但它使用 javax.xml.stream 中的本地库,而 Android 中没有这些库。当我尝试使用行 compile 'javax.xml.stream:stax-api:1.0-2' 手动将它们包含在我的 build.gradle 文件中时,Android studio 给我这个关于使用本机库的非常描述性的错误:

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.

<Information about how to override this warning and why it's a bad idea>

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.

当我不手动包含这些库时,我在运行时遇到此异常:

 java.lang.ClassNotFoundException: Didn't find class "javax.xml.stream.XMLEventFactory" on path: DexPathList[[zip file "/data/app/<package>"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
            at org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.<clinit>(PackagePropertiesMarshaller.java:41)
            at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:162)
            at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:142)
            at org.apache.poi.openxml4j.opc.Package.<init>(Package.java:37)
            at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:89)
            at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:273)
            at org.apache.poi.util.PackageHelper.open(PackageHelper.java:37)
            at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:123)

当运行如下代码:

XWPFDocument wordDocument = new XWPFDocument(new FileInputStream(wordFileName));

其中 wordFileName 是 word 文档的有效路径。

所以我的问题是:是否可以在 Android 上使用 Apache XWPF,如果不能,我可以使用什么来将 docx 文件转换为 html?

我无法让 Apache XWPF 正常工作,但我可以使用 Docx4j(Android here 的示例代码),它对我的​​目的有用。我只需要包含在该项目中找到的库。