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

戏子无情 提交于 2019-12-18 03:56:56

问题


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!


回答1:


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>



回答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.




回答3:


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



来源:https://stackoverflow.com/questions/5964668/android-error-including-repacking-dependencies-which-reference-javax-core-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!