Skip to content

Conversation

@lakor64
Copy link

@lakor64 lakor64 commented Oct 23, 2025

The following code adds JAXB marshalling and unmarshalling support for Android Java runtime, as ART is implemented differently than a standard Openjdk implementation.

StackWalker is present in Android API since API Level 34 (Android 14) which approximately 50% of devices currently supports, which is why I have decided to provide an alternative implementation for older API levels (based from the previous Jakarta code before bumping to Jdk11)

Android does not provide any implementation for java.awt.*, which is why I check during runtime if this classes are present,
Android also does not provide a StaX implementation, which is why I added an extra StaX dependency found online, I belive if there is any interest to remove StaX dependency for Android it whould be done on another PR.

Android also, does not support Java 9+ modules, according to the previous code of MUtils the function was empty before switching to Jdk9, which is where I replicate such behaviour.

All maven tests passes.

Relevant code that was tested under Android:

    public static <T> void marshalRes(T req, Writer in) throws JAXBException, IOException {
        JAXBContext ctx = JAXBContext.newInstance(req.getClass());
        Marshaller m = ctx.createMarshaller();
        StringWriter w = new StringWriter();
        m.marshal(req, w);
        String p = w.toString();
        in.write(p);
    }

without this edits, JAXBContext.newInstance would crash, while on Openjdk it would work as intended.

Extra environment information for replicating marshaller/unmarshaller tests:

  • Gradle: 9.1.0 /w AGP 8.13.0
  • Min SDK: 24
  • Max SDK: 34
  • Compile SDK: 36
  • Desugaring enabled with source and target version set to Java 11
  • Successfully run on Android 7.1

Dependencies added:

  • org.glassfish.jaxb:jaxb-core with this patches
  • org.glassfish.jaxb:jaxb-runtime with this patches
  • jakarta.xml.bind:jakarta.xml.bind-api:4.0.4
  • javax.xml.stream:stax-api:1.0-2

@laurentschoelens
Copy link
Contributor

Hello @lakor64

Thanks for provided PR but :

  • could you create an issue to track down your problem before submitting PR
  • you need to accept ECA for PR to pass
  • I'll have some remarks on work done on your PR

Regards

@lakor64
Copy link
Author

lakor64 commented Oct 23, 2025

Hello, I've signed the ECA and created the issue #1870

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

Successfully merging this pull request may close these issues.

2 participants