我用
生成了绝对空的Android项目mvn archetype:generate -DarchetypeArtifactId=android-quickstart .......
它构建良好,它部署良好,它运行良好。问题是,当我添加
时 <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-plugin 2. *之前 - 结果是一样的。这仅对simple-xml
依赖性失败。禁用codegist-crest
启用simple-xml
可以正常工作。只有在我使用simple-xml
时才会发生这种情况。
我也试过在没有maven(Eclipse)的情况下做同样的事情 - 在这种情况下一切正常,即使我的构建路径上有simple-xml
。
有什么想法吗?
答案 0 :(得分:4)
这里的问题是simple-xml
或更可能是其中一个依赖项已经在保留的java。*或javax。*命名空间中定义了一个或多个类。这在Android平台上是不允许的。虽然,我不知道为什么这会在Eclipse中起作用。库是否可能在构建路径上但未包含在最终编译的APK中?
由于Android平台提供了许多与XML相关的软件包,因此您可能不需要simple-xml
:
<强>更新强>
以下SO问题和答案介绍了如何包含simple-xml
库但禁用其依赖的冲突导入:Android: error including/repacking dependencies which reference javax core classes
答案 1 :(得分:0)
最好的方法就是使用此配置项 http://jayway.github.io/maven-android-plugin/dex-mojo.html#dexCoreLibrary android-maven-plugin
因此,您可以将其添加到插件的<config>
部分:
<dexCoreLibrary>true</dexCoreLibrary>
或定义
<android.dex.coreLibrary>true</android.dex.coreLibrary>
在<properties>
部分。