2011-12-13 52 views
3

失败,我有大厦Android项目与Maven - dexer简单的XML依赖

mvn archetype:generate -DarchetypeArtifactId=android-quickstart ....... 

它建立精细产生空空如也的Android项目,它部署罚款和它运行良好。问题是,当我添加

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

到依赖性,构建失败,

[INFO] --- android-maven-plugin:3.0.0:dex (default-dex) @ whoops-android-app1 --- 
[INFO] C:\Program Files\Java\jdk1.7.0\jre\bin\java [-jar, D:\android-sdk\platform-tools\lib\dx.jar, --dex, --output=D:\whoops\xxx\whoops-android-app1\target\classes.dex, C:\Users\loki2302\.m2\repository\xpp3\xpp3\1.1.4c\xpp3-1.1.4c.jar, C:\Users\loki2302\.m2\repository\org\simpleframework\simple-xml\2.6.2\simple-xml-2.6.2.jar, C:\Users\loki2302\.m2\repository\stax\stax\1.2.0\stax-1.2.0.jar, C:\Users\loki2302\.m2\repository\stax\stax-api\1.0.1\stax-api-1.0.1.jar, D:\whoops\xxx\whoops-android-app1\target\classes] 
[INFO] 
[INFO] trouble processing "javax/xml/namespace/QName.class": 
[INFO] 
[INFO] Ill-advised or mistaken usage of a core class (java.* or javax.*) 
[INFO] when not building a core library. 
[INFO] 
[INFO] This is often due to inadvertently including a core library file 
[INFO] in your application's project, when using an IDE (such as 
[INFO] Eclipse). If you are sure you're not intentionally defining a 
[INFO] core class, then this is the most likely explanation of what's 
[INFO] going on. 
[INFO] 
[INFO] However, you might actually be trying to define a class in a core 
[INFO] namespace, the source of which you may have taken, for example, 
[INFO] from a non-Android virtual machine project. This will most 
[INFO] assuredly not work. At a minimum, it jeopardizes the 
[INFO] compatibility of your app with future versions of the platform. 
[INFO] It is also often of questionable legality. 
[INFO] 
[INFO] If you really intend to build a core library -- which is only 
[INFO] appropriate as part of creating a full virtual machine 
[INFO] distribution, as opposed to compiling an application -- then use 
[INFO] the "--core-library" option to suppress this error message. 
[INFO] 
[INFO] If you go ahead and use "--core-library" but are in fact 
[INFO] building an application, then be forewarned that your application 
[INFO] will still fail to build or run, at some point. Please be 
[INFO] prepared for angry customers who find, for example, that your 
[INFO] application ceases to function once they upgrade their operating 
[INFO] system. You will be to blame for this problem. 
[INFO] 
[INFO] If you are legitimately using some code that happens to be in a 
[INFO] core package, then the easiest safe alternative you have is to 
[INFO] repackage that code. That is, move the classes in question into 
[INFO] your own package namespace. This means that they will never be in 
[INFO] conflict with core system classes. JarJar is a tool that may help 
[INFO] you in this endeavor. If you find that you cannot do this, then 
[INFO] that is an indication that the path you are on will ultimately 
[INFO] lead to pain, suffering, grief, and lamentation. 
[INFO] 
[INFO] 1 error; aborting 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 2.711s 
[INFO] Finished at: Tue Dec 13 12:31:23 MSK 2011 
[INFO] Final Memory: 18M/178M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.0.0:dex (default-dex) on project whoops-android-app1: MojoExecutionException: ANDROID-040-001: Could not execute: Command = cmd.exe /X /C ""C:\Program Files\Java\jdk1.7.0\jre\bin\java" -jar D:\android-sdk\platform-tools\lib\dx.jar --dex --output=D:\whoops\xxx\whoops-android-app1\target\classes.dex C:\Users\loki2302\.m2\repository\xpp3\xpp3\1.1.4c\xpp3-1.1.4c.jar C:\Users\loki2302\.m2\repository\org\simpleframework\simple-xml\2.6.2\simple-xml-2.6.2.jar C:\Users\loki2302\.m2\repository\stax\stax\1.2.0\stax-1.2.0.jar C:\Users\loki2302\.m2\repository\stax\stax-api\1.0.1\stax-api-1.0.1.jar D:\whoops\xxx\whoops-android-app1\target\classes", Result = 1 -> [Help 1] 

删除此依赖修复版本。这里是我的mvn --version

Apache Maven 3.0.3 (r1075438; 2011-02-28 20:31:09+0300) 
Maven home: D:\apache-maven-3.0.3\bin\.. 
Java version: 1.7.0, vendor: Oracle Corporation 
Java home: C:\Program Files\Java\jdk1.7.0\jre 
Default locale: en_US, platform encoding: Cp1251 
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows" 

这里是我的pom.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.whoops.android</groupId> 
    <artifactId>whoops-android-app1</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>apk</packaging> 
    <name>whoops-android-app1</name> 

    <dependencies> 
     <dependency> 
      <groupId>com.google.android</groupId> 
      <artifactId>android</artifactId> 
      <version>2.1.2</version> 
      <scope>provided</scope> 
     </dependency> 

     <!-- <dependency>   
      <groupId>org.codegist.crest</groupId> 
      <artifactId>codegist-crest</artifactId> 
      <version>2.0.0-RC1</version>   
     </dependency> --> 

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

    <build> 
     <plugins> 
      <plugin> 
       <groupId>com.jayway.maven.plugins.android.generation2</groupId> 
       <artifactId>android-maven-plugin</artifactId> 
       <version>3.0.0</version> 
       <configuration> 
        <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile> 
        <assetsDirectory>${project.basedir}/assets</assetsDirectory> 
        <resourceDirectory>${project.basedir}/res</resourceDirectory> 
        <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory> 
        <sdk> 
         <platform>7</platform> 
        </sdk> 
        <deleteConflictingFiles>true</deleteConflictingFiles> 
        <undeployBeforeDeploy>true</undeployBeforeDeploy> 
       </configuration> 
       <extensions>true</extensions> 
      </plugin> 
      <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.3.2</version> 
       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

试过的Maven 2和Maven的Android的插件2. *之前 - 的结果是一样的。这仅仅对simple-xml依赖关系失败。启用codegist-crestsimple-xml禁用工作正常。只有当我使用simple-xml时才会发生这种情况。

我也试着做同样没有maven(Eclipse) - 在这种情况下,一切工作正常,即使我在我的构建路径上有simple-xml

任何想法?

回答

4

这里的问题在于simple-xml或更可能是其中一个依赖项在保留的java。*或javax。*命名空间中定义了一个或多个类。这在Android平台上是不允许的。虽然,我不确定为什么这可以在Eclipse中工作。库有没有可能在构建路径上,但未包含在最终编译的APK中?

这可能是你不需要simple-xml为Android平台提供了大量的XML相关的包:

更新:

以下SO问题和答案描述了如何包括simple-xml库,但禁用冲突的进口取决于下列因素:Android: error including/repacking dependencies which reference javax core classes

+0

看起来你是绝对正确的。问题是,我使用需要simple-xml的CRest来处理我的服务。我只是感到困惑,因为“CRest为Android平台提供了开箱即用的支持。” (http://crest.codegist.org/deeper/android.html) – agibalov

+0

我已经更新了我的答案,并附上了您正在寻找的解决方案的SO问题链接。基本上你可以导入'simple-xml'库,但不包括它依赖的冲突依赖关系。 –