【问题标题】:Issue with Android Maven PluginAndroid Maven 插件问题
【发布时间】:2014-09-05 06:50:55
【问题描述】:

我对 maven 在 android 上的管理依赖关系非常陌生。实际上我在新的 Android Studio 中实现了使用 Gradle 配置管理配置依赖项,但我没有实现配置 pom.xml 以使用此插件进行部署。

我的 pom.xml 看起来像

<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.company</groupId>
<artifactId>my-project</artifactId>
<version>1.0.0</version>
<packaging>apk</packaging>
<name>${project.artifactId}</name>
<url>http://maven.apache.org</url>

<!-- Repositories Configuration -->
<repositories>
    <!-- Spring Maven Release Repository -->
    <repository>
        <id>org.springframework.maven.release</id>
        <name>Spring Maven Release Repository</name>
        <url>http://repo.springsource.org/release</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
    <!-- For testing against latest Spring snapshots -->
    <repository>
        <id>org.springframework.maven.snapshot</id>
        <name>Spring Maven Snapshot Repository</name>
        <url>http://repo.springsource.org/snapshot</url>
        <releases>
            <enabled>false</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <!-- For developing against latest Spring milestones -->
    <repository>
        <id>org.springframework.maven.milestone</id>
        <name>Spring Maven Milestone Repository</name>
        <url>http://repo.springsource.org/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
    <!-- Maven Central Repository -->
    <repository>
        <id>Central Repository</id>
        <url>http://repo.maven.apache.org/maven2</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

<!-- Project Properties -->
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.7</java.version>    
    <android.sdk.platform>19</android.sdk.platform>
</properties>

<!-- Dependencies -->
<dependencies>
<!-- Android -->
<dependency>
  <groupId>com.google.android</groupId>
  <artifactId>android</artifactId>
  <version>4.1.1.4</version>
</dependency>
<!-- Spring -->
<dependency>
  <groupId>org.springframework.android</groupId>
  <artifactId>spring-android-rest-template</artifactId>
  <version>1.0.1.RELEASE</version>
</dependency>
<!-- Json -->
<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-databind</artifactId>
  <version>2.4.2</version>
</dependency>
</dependencies>
<!-- Build -->
<build>
<finalName>${project.artifactId}</finalName>
<sourceDirectory>app/src</sourceDirectory>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <inherited>true</inherited>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
        </plugin>
        <!-- Facilitates downloading source and javadoc in Eclipse -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-eclipse-plugin</artifactId>
            <version>2.9</version>
            <configuration>
                <wtpversion>2.0</wtpversion>
                <downloadSources>true</downloadSources>
                <downloadJavadocs>true</downloadJavadocs>
            </configuration>
        </plugin>
     <!-- Android -->
        <plugin>
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <version>3.8.2</version>
            <configuration>
      <androidManifestFile>app/src/main/AndroidManifest.xml</androidManifestFile>
      <resourceDirectory>app/src/main/res</resourceDirectory>
      <assetsDirectory>app/src/main/assets</assetsDirectory>
                <sdk>
        <path>${env.ANDROID_HOME}</path>
                    <platform>${android.sdk.platform}</platform>
                </sdk>
      <dex>
        <jvmArguments>
          <jvmArgument>-Xms256m</jvmArgument>
          <jvmArgument>-Xmx512m</jvmArgument>
        </jvmArguments>
      </dex>          
      <emulator>
        <avd>Nexus4</avd>
      </emulator>
      <attachJar>auto</attachJar>
                <deleteConflictingFiles>true</deleteConflictingFiles>
                <undeployBeforeDeploy>true</undeployBeforeDeploy>
            </configuration>
            <extensions>true</extensions>
        </plugin>
</plugins>
</build>

</project>

但是每次我运行命令 mvn clean package 我都会收到这个错误

[ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:andr
    oid-maven-plugin:3.8.2:dex (default-dex) on project stock-control: MojoExecution
    Exception: ANDROID-040-001: Could not execute: Command = cmd.exe /X /C "c:\Java\
    jdk1.7.0_67\jre\bin\java -Xms256m -Xmx512m -jar X:\development\android-studio\sd
    k\build-tools\android-4.4W\lib\dx.jar --dex --output=X:\google-drive\work\projec
    ts\leibran\android\stock-control\application\src\stock-control\target\classes.de
    x C:\home\m2\repository\commons-codec\commons-codec\1.3\commons-codec-1.3.jar C:
    \home\m2\repository\com\fasterxml\jackson\core\jackson-databind\2.4.2\jackson-da
    tabind-2.4.2.jar C:\home\m2\repository\org\json\json\20080701\json-20080701.jar
    C:\home\m2\repository\org\apache\httpcomponents\httpclient\4.0.1\httpclient-4.0.
    1.jar C:\home\m2\repository\com\fasterxml\jackson\core\jackson-core\2.4.2\jackso
    n-core-2.4.2.jar C:\home\m2\repository\commons-logging\commons-logging\1.1.1\com
    mons-logging-1.1.1.jar C:\home\m2\repository\xerces\xmlParserAPIs\2.6.2\xmlParse
    rAPIs-2.6.2.jar C:\home\m2\repository\org\apache\httpcomponents\httpcore\4.0.1\h
    ttpcore-4.0.1.jar C:\home\m2\repository\xpp3\xpp3\1.1.4c\xpp3-1.1.4c.jar C:\home
    \m2\repository\org\khronos\opengl-api\gl1.1-android-2.1_r1\opengl-api-gl1.1-andr
    oid-2.1_r1.jar C:\home\m2\repository\org\springframework\android\spring-android-
    rest-template\1.0.1.RELEASE\spring-android-rest-template-1.0.1.RELEASE.jar C:\ho
    me\m2\repository\org\springframework\android\spring-android-core\1.0.1.RELEASE\s
    pring-android-core-1.0.1.RELEASE.jar C:\home\m2\repository\com\fasterxml\jackson
    \core\jackson-annotations\2.4.0\jackson-annotations-2.4.0.jar X:\google-drive\wo
    rk\projects\leibran\android\stock-control\application\src\stock-control\target\c
    lasses C:\home\m2\repository\com\google\android\android\4.1.1.4\android-4.1.1.4.
    jar", Result = 1 -> [Help 1]
    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal c
    om.jayway.maven.plugins.android.generation2:android-maven-plugin:3.8.2:dex (defa
    ult-dex) on project stock-control:
            at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
    .java:216)
            at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
    .java:153)
            at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
    .java:145)
            at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
    ct(LifecycleModuleBuilder.java:116)
            at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
    ct(LifecycleModuleBuilder.java:80)
            at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThre
    adedBuilder.build(SingleThreadedBuilder.java:51)
            at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(Lifecycl
    eStarter.java:120)
            at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)
            at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
            at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
            at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
            at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:606)
            at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Laun
    cher.java:289)
            at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav
    a:229)
            at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(La
    uncher.java:415)
            at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:
    356)
    Caused by: org.apache.maven.plugin.MojoExecutionException:
            at com.jayway.maven.plugins.android.phase08preparepackage.DexMojo.runDex
    (DexMojo.java:411)
            at com.jayway.maven.plugins.android.phase08preparepackage.DexMojo.execut
    e(DexMojo.java:159)
            at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(Default
    BuildPluginManager.java:132)
            at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
    .java:208)
            ... 19 more
    Caused by: com.jayway.maven.plugins.android.ExecutionException: ANDROID-040-001:
     Could not execute: Command = cmd.exe /X /C "c:\Java\jdk1.7.0_67\jre\bin\java -X
    ms256m -Xmx512m -jar X:\development\android-studio\sdk\build-tools\android-4.4W\
    lib\dx.jar --dex --output=X:\google-drive\work\projects\leibran\android\stock-co
    ntrol\application\src\stock-control\target\classes.dex C:\home\m2\repository\com
    mons-codec\commons-codec\1.3\commons-codec-1.3.jar C:\home\m2\repository\com\fas
    terxml\jackson\core\jackson-databind\2.4.2\jackson-databind-2.4.2.jar C:\home\m2
    \repository\org\json\json\20080701\json-20080701.jar C:\home\m2\repository\org\a
    pache\httpcomponents\httpclient\4.0.1\httpclient-4.0.1.jar C:\home\m2\repository
    \com\fasterxml\jackson\core\jackson-core\2.4.2\jackson-core-2.4.2.jar C:\home\m2
    \repository\commons-logging\commons-logging\1.1.1\commons-logging-1.1.1.jar C:\h
    ome\m2\repository\xerces\xmlParserAPIs\2.6.2\xmlParserAPIs-2.6.2.jar C:\home\m2\
    repository\org\apache\httpcomponents\httpcore\4.0.1\httpcore-4.0.1.jar C:\home\m
    2\repository\xpp3\xpp3\1.1.4c\xpp3-1.1.4c.jar C:\home\m2\repository\org\khronos\
    opengl-api\gl1.1-android-2.1_r1\opengl-api-gl1.1-android-2.1_r1.jar C:\home\m2\r
    epository\org\springframework\android\spring-android-rest-template\1.0.1.RELEASE
    \spring-android-rest-template-1.0.1.RELEASE.jar C:\home\m2\repository\org\spring
    framework\android\spring-android-core\1.0.1.RELEASE\spring-android-core-1.0.1.RE
    LEASE.jar C:\home\m2\repository\com\fasterxml\jackson\core\jackson-annotations\2
    .4.0\jackson-annotations-2.4.0.jar X:\google-drive\work\projects\leibran\android
    \stock-control\application\src\stock-control\target\classes C:\home\m2\repositor
    y\com\google\android\android\4.1.1.4\android-4.1.1.4.jar", Result = 1
            at com.jayway.maven.plugins.android.CommandExecutor$Factory$DefaultComma
    ndExecutor.executeCommand(CommandExecutor.java:246)
            at com.jayway.maven.plugins.android.phase08preparepackage.DexMojo.runDex
    (DexMojo.java:407)
            ... 22 more
    [ERROR]
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please rea
    d the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionE
    xception

有人可以帮帮我吗?

谢谢

编辑

@MirMasej,我按照您在评论中指定的步骤进行操作,我明白了。

C:\Java\jdk1.7.0_67\jre\bin> cmd.exe /X /C "c:\Java\jdk1.7.0_67\jre\bin\java -Xm
s256m -Xmx512m -jar X:\development\android-studio\sdk\build-tools\android-4.4W\l
ib\dx.jar --dex --output=X:\google-drive\work\projects\leibran\android\stock-con
trol\application\src\stock-control\target\classes.dex C:\home\m2\repository\comm
ons-codec\commons-codec\1.3\commons-codec-1.3.jar C:\home\m2\repository\com\fast
erxml\jackson\core\jackson-databind\2.4.2\jackson-databind-2.4.2.jar C:\home\m2\
repository\org\json\json\20080701\json-20080701.jar C:\home\m2\repository\org\ap
ache\httpcomponents\httpclient\4.0.1\httpclient-4.0.1.jar C:\home\m2\repository\
com\fasterxml\jackson\core\jackson-core\2.4.2\jackson-core-2.4.2.jar C:\home\m2\
repository\commons-logging\commons-logging\1.1.1\commons-logging-1.1.1.jar C:\ho
me\m2\repository\xerces\xmlParserAPIs\2.6.2\xmlParserAPIs-2.6.2.jar C:\home\m2\r
epository\org\apache\httpcomponents\httpcore\4.0.1\httpcore-4.0.1.jar C:\home\m2
\repository\xpp3\xpp3\1.1.4c\xpp3-1.1.4c.jar C:\home\m2\repository\org\khronos\o
pengl-api\gl1.1-android-2.1_r1\opengl-api-gl1.1-android-2.1_r1.jar C:\home\m2\re
pository\org\springframework\android\spring-android-rest-template\1.0.1.RELEASE\
spring-android-rest-template-1.0.1.RELEASE.jar C:\home\m2\repository\org\springf
ramework\android\spring-android-core\1.0.1.RELEASE\spring-android-core-1.0.1.REL
EASE.jar C:\home\m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.
4.0\jackson-annotations-2.4.0.jar X:\google-drive\work\projects\leibran\android\
stock-control\application\src\stock-control\target\classes C:\home\m2\repository
\com\google\android\android\4.1.1.4\android-4.1.1.4.jar
warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.commons.logging.impl.LogFactoryImpl$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.commons.logging.impl.LogFactoryImpl$2) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.commons.logging.impl.LogFactoryImpl$3) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.commons.logging.impl.SimpleLog$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.commons.logging.impl.WeakHashtable$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.commons.logging.LogFactory$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.commons.logging.LogFactory$2) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.commons.logging.LogFactory$3) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.commons.logging.LogFactory$4) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.commons.logging.LogFactory$5) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.commons.logging.LogFactory$6) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.

trouble processing "javax/xml/parsers/DocumentBuilder.class":

Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.

This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most likely explanation of what's
going on.

However, you might actually be trying to define a class in a core
namespace, the source of which you may have taken, for example,
from a non-Android virtual machine project. This will most
assuredly not work. At a minimum, it jeopardizes the
compatibility of your app with future versions of the platform.
It is also often of questionable legality.

If you really intend to build a core library -- which is only
appropriate as part of creating a full virtual machine
distribution, as opposed to compiling an application -- then use
the "--core-library" option to suppress this error message.

If you go ahead and use "--core-library" but are in fact
building an application, then be forewarned that your application
will still fail to build or run, at some point. Please be
prepared for angry customers who find, for example, that your
application ceases to function once they upgrade their operating
system. You will be to blame for this problem.

If you are legitimately using some code that happens to be in a
core package, then the easiest safe alternative you have is to
repackage that code. That is, move the classes in question into
your own package namespace. This means that they will never be in
conflict with core system classes. JarJar is a tool that may help
you in this endeavor. If you find that you cannot do this, then
that is an indication that the path you are on will ultimately
lead to pain, suffering, grief, and lamentation.

1 error; aborting

【问题讨论】:

    标签: java android maven android-studio


    【解决方案1】:

    检查是否有java

    “c:\Java\jdk1.7.0_67\jre\bin\java”。

    如果是,请尝试运行 maven 打印的整个命令:

    cmd.exe /X /C "c:\Java\ blah blah blah android\4.1.1.4\android-4.1.1.4.jar"

    从命令行查看消息。

    【讨论】:

    • 我遇到了一个错误,我更新了我的问题以了解您是否知道如何解决。谢谢。
    • @edla.sk8 见this answer。 android.4.1.1.4.jar 不应该在你的类路径中。
    • 我检查了我的 .m2 家,罐子在那里
    • 我很确定它就在那里。尝试为您的 android 依赖项添加提供的范围:provided
    猜你喜欢
    • 1970-01-01
    • 2011-11-29
    • 1970-01-01
    • 2014-05-03
    • 1970-01-01
    • 1970-01-01
    • 2017-08-27
    • 2019-03-30
    • 2011-03-20
    相关资源
    最近更新 更多