Search code examples
javaandroidmavensimple-frameworkjarjar

Android: error including/repacking dependencies which reference javax core classes


I'm working on an Android app using Maven as the build tool. I managed to set evertyhing up correctly (maven dependencies are exported to the apk etc.), however I have one remaining problem which is driving me crazy.

I want to include a dependency on simpleframework's xml parser defined as follows in my POM file:

<dependency>
    <groupId>org.simpleframework</groupId> 
    <artifactId>simple-xml</artifactId>
    <version>2.5.3</version>
</dependency>

When I issue mvn install on the project, I get the following error (truncated):

trouble processing "javax/xml/namespace/NameSpaceContext.class" ...

I know the error results from the simple xml parser referencing these javax-classes, however I haven't found a solution yet (setting the --core-library flag is of no use).

I'm currently trying to repack the dependency with the maven-jarjar-pluging but this doesn't seem to work either.

Can anyone help me out with this? Many, many thanks in advance!


Solution

  • Define your simple-xml depedency like this :

    <dependency>
        <groupId>org.simpleframework</groupId>
        <artifactId>simple-xml</artifactId>
        <version>2.6.1</version>
        <exclusions>
            <!-- StAX is not available on Android -->
            <exclusion>
                <artifactId>stax</artifactId>
                <groupId>stax</groupId>
            </exclusion>
            <exclusion>
                <artifactId>stax-api</artifactId>
                <groupId>stax</groupId>
            </exclusion>
            <!-- Provided by Android -->
            <exclusion>
                <artifactId>xpp3</artifactId>
                <groupId>xpp3</groupId>
            </exclusion>
        </exclusions>
    </dependency>