Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android support #293

Open
Junzz0 opened this issue May 20, 2024 · 3 comments
Open

Android support #293

Junzz0 opened this issue May 20, 2024 · 3 comments

Comments

@Junzz0
Copy link

Junzz0 commented May 20, 2024

Sorry, because I clicked the wrong order and it closed #292 .

When I manually add the following dependencies,

implementation("xerces:xercesImpl:2.12.2")
implementation("com.fasterxml.woodstox:woodstox-core:6.6.2")

java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/xerces/dom/DocumentImpl;error will not be reported.

I call

val odt = OdfTextDocument.newTextDocument()

odt.addText("TEST")

application.contentResolver
.openFileDescriptor(path.toUri(), "w")
.use { pfd -> odt.save(ParcelFileDescriptor.AutoCloseOutputStream(pfd)) }

,The following error will be reported:
java.lang.NoSuchMethodError: No static method newFactory()Ljavax/xml/stream/XMLOutputFactory; in class Ljavax/xml/stream/XMLOutputFactory; or its super classes (declaration of 'javax.xml.stream.XMLOutputFactory' appears in dex)
at org.odftoolkit.odfdom.pkg.rdfa.DOMRDFaParser.(DOMRDFaParser.java:34)
at org.odftoolkit.odfdom.pkg.rdfa.DOMRDFaParser.createInstance(DOMRDFaParser.java:38)
at org.odftoolkit.odfdom.pkg.OdfFileDom.updateInContentMetadataCache(OdfFileDom.java:699)
at org.odftoolkit.odfdom.dom.element.text.TextPElement.onInsertNode(TextPElement.java:114)
at org.odftoolkit.odfdom.pkg.OdfElement.onInsertNode(OdfElement.java:783)
at org.odftoolkit.odfdom.pkg.OdfElement.insertBefore(OdfElement.java:794)
at org.apache.xerces.dom.NodeImpl.appendChild(Unknown Source:1)
at org.odftoolkit.odfdom.pkg.OdfElement.appendChild(OdfElement.java:589)
at org.odftoolkit.odfdom.pkg.OdfFileSaxHandler.startElement(OdfFileSaxHandler.java:137)
at org.odftoolkit.odfdom.pkg.rdfa.MultiContentHandler.startElement(MultiContentHandler.java:76)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source:146)
at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source:0)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source:427)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source:514)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source:15)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source:79)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source:11)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source:5)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source:35)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source:41)
at org.odftoolkit.odfdom.pkg.OdfFileDom.initialize(OdfFileDom.java:236)
at org.odftoolkit.odfdom.dom.OdfContentDom.initialize(OdfContentDom.java:74)
at org.odftoolkit.odfdom.pkg.OdfFileDom.(OdfFileDom.java:102)
at org.odftoolkit.odfdom.dom.OdfContentOrStylesDomBase.(OdfContentOrStylesDomBase.java:45)
at org.odftoolkit.odfdom.dom.OdfContentDom.(OdfContentDom.java:59)
at org.odftoolkit.odfdom.dom.OdfSchemaDocument.getContentDom(OdfSchemaDocument.java:418)
at org.odftoolkit.odfdom.doc.OdfDocument.getContentRoot(OdfDocument.java:737)
at org.odftoolkit.odfdom.doc.OdfTextDocument.getContentRoot(OdfTextDocument.java:321)
at org.odftoolkit.odfdom.doc.OdfTextDocument.addText(OdfTextDocument.java:357)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:111)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:99)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:811)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:715)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:702)
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@e56a0d2, Dispatchers.IO]

@Junzz0
Copy link
Author

Junzz0 commented May 20, 2024

Check that xml-apis has been imported, but the https://developer.android.com/reference/packages Android documentation does not have the javax.xml.stream package, so I'm not sure if it's because xml-apis doesn't support Android.

@Junzz0
Copy link
Author

Junzz0 commented May 20, 2024

If the official is willing to be compatible with Android, I still hope to get help.

@svanteschubert
Copy link
Contributor

If you look into the error stack above, you see that the following call does not exist in your Android:
XMLOutputFactory.newFactory()
being called from
https://github.com/tdf/odftoolkit/blob/master/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/rdfa/DOMRDFaParser.java#L34
the method is available in JDK 11:
https://docs.oracle.com/en/java/javase/11/docs/api/java.xml/javax/xml/stream/XMLOutputFactory.html#newFactory()

But it seems Android does not support the full JDK functionality:
https://stackoverflow.com/questions/5176028/how-writing-xml-file-usning-xmlstreamwriter-in-android

To me, it is fine to support Android and would review any pull requested that you might provide, but I am too occupied to pursue this task myself. But perhaps others might be interested as well.

Godspeed!
Svante

PS: For next time, I accidentally closed issues as well, but you may reopen them in the future - but no problem we can continue here... :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants