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

3

14

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!

Mezoff answered 11/5, 2011 at 13:0 Comment(0)
C
28

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>
Centenarian answered 6/9, 2011 at 8:39 Comment(3)
Thanks for your reply. I'm not currently working on the project, but I'll keep it in mind for future use. If it works then, I'll come back and make sure to accept this answer :)Mezoff
Trying this solution but I still have a org.simpleframwork.xml.core.Persister not found error.Trigraph
@Henryk Konsekwhere do you place an xml dependency like this? what folder?Ado
I
2

I use android-maven-plugin, and adding <coreLibrary>true</coreLibrary> to the <configuration> tag of the plugin in the POM works for me. However, there's a bug: https://github.com/jayway/maven-android-plugin/pull/34, that you need to include to fix the plugin you are using, since the bug won't be fixed until 3.0. Here's how I got it working for me using 2.9.0-SNAPSHOT.

  1. add a pluginRepository pointing to http:// oss.sonatype.org/content/repositories/jayway-snapshots/ to get 2.9.0-SNAPSHOT
  2. update your plugin version to use 2.9.0-SNAPSHOT and add <coreLibrary>true</coreLibrary> to pom.xml
  3. get the fix: git clone https://github.com/kevinpotgieter/maven-android-plugin.git
  4. remove src/test/java/com: so the test won't fail
  5. mvn package
  6. copy it and overwrite your local maven cache in .m2 (You may need to remove your plugin repository yours gets overwritten every time.)

Step 3-6 won't be necessary after the fix gets into 2.9.0-SNAPSHOT.


Update July 2010: 2.9.0-beta-4 has the fix, so you don't need the above workaround if you use 2.9.0-beta-4 or later. I tested 2.9.0-beta-5 which worked just fine.

Idyllist answered 21/5, 2011 at 22:23 Comment(0)
P
1

Spring Android uses Maven to integrate Simple. Take a look at the following URL, it should provide pointers on how to get Maven working with Simple.

http://static.springsource.org/spring-android/docs/1.0.x/reference/html/rest-template.html

Phillisphilly answered 1/6, 2011 at 1:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.