MojoExecutionException:Maven with Android

时间:2014-03-25 21:42:37

标签: java android maven exception maven-plugin

我正在使用Android Studio和Maven 3.1.1,并且在程序包目标中它会因MojoExecutionException而崩溃。我已经发了很多帖子,但我无法得到解决方案。

[错误]生成来源时出错。

org.apache.maven.plugin.MojoExecutionException: 
    at com.jayway.maven.plugins.android.phase01generatesources.GenerateSourcesMojo.generateR(GenerateSourcesMojo.java:593)
    at com.jayway.maven.plugins.android.phase01generatesources.GenerateSourcesMojo.execute(GenerateSourcesMojo.java:216)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    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.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: com.jayway.maven.plugins.android.ExecutionException: ANDROID-040-001: Could not execute: Command = cmd.exe /X /C "C:\Users\hvalls\AppData\Local\Android\android-studio\sdk\build-tools\19.0.3\aapt.exe package -f --no-crunch -I C:\Users\hvalls\AppData\Local\Android\android-studio\sdk\platforms\android-19\android.jar -M C:\Users\hvalls\Desktop\my-app\AndroidManifest.xml -S C:\Users\hvalls\Desktop\my-app\res -A C:\Users\hvalls\Desktop\my-app\target\generated-sources\combined-assets\assets -m -J C:\Users\hvalls\Desktop\my-app\target\generated-sources\r --output-text-symbols C:\Users\hvalls\Desktop\my-app\target --auto-add-overlay", Result = -1073741819
    at com.jayway.maven.plugins.android.CommandExecutor$Factory$DefaultCommandExecutor.executeCommand(CommandExecutor.java:246)
    at com.jayway.maven.plugins.android.phase01generatesources.GenerateSourcesMojo.generateR(GenerateSourcesMojo.java:589)
    ... 28 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 16.665s
[INFO] Finished at: Tue Mar 25 22:32:34 CET 2014
[INFO] Final Memory: 19M/184M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.8.2:generate-sources (default-generate-sources) on project my-app: MojoExecutionException: ANDROID-040-001: Could not execute: Command = cmd.exe /X /C "C:\Users\hvalls\AppData\Local\Android\android-studio\sdk\build-tools\19.0.3\aapt.exe package -f --no-crunch -I C:\Users\hvalls\AppData\Local\Android\android-studio\sdk\platforms\android-19\android.jar -M C:\Users\hvalls\Desktop\my-app\AndroidManifest.xml -S C:\Users\hvalls\Desktop\my-app\res -A C:\Users\hvalls\Desktop\my-app\target\generated-sources\combined-assets\assets -m -J C:\Users\hvalls\Desktop\my-app\target\generated-sources\r --output-text-symbols C:\Users\hvalls\Desktop\my-app\target --auto-add-overlay", Result = -1073741819 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Process finished with exit code 1

的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://maven.apache.org/POM/4.0.0"
    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.android.app</groupId>
    <artifactId>my-app</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>apk</packaging>
    <name>my-app</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <platform.version>4.1.1.4
        </platform.version>
        <android.plugin.version>3.8.2</android.plugin.version>
    </properties>

    <dependencies>
        <!--Android Annotations-->
        <dependency>
            <groupId>com.googlecode.androidannotations</groupId>
            <artifactId>androidannotations-api</artifactId>
            <version>2.7.1</version>
        </dependency>
        <dependency>
            <groupId>com.googlecode.androidannotations</groupId>
            <artifactId>androidannotations</artifactId>
            <version>2.7.1</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>${platform.version}</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <finalName>${project.artifactId}</finalName>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                    <artifactId>android-maven-plugin</artifactId>
                    <version>${android.plugin.version}</version>
                    <extensions>true</extensions>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <version>3.8.2</version>
                <configuration>
                    <sdk>
                        <platform>19</platform>
                    </sdk>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

3 个答案:

答案 0 :(得分:7)

这个问题有点棘手,但可以解决!

首先,当你收到类似你所获得的错误消息时,你应该尝试运行Maven说它无法运行的命令,因为在maven下载依赖项并构建代码等之后.. Maven它自己运行初始命令制作你的apk。在你的情况下它是:

C:\Users\hvalls\AppData\Local\Android\android-studio\sdk\build-tools\19.0.3\aapt.exe package -f --no-crunch -I C:\Users\hvalls\AppData\Local\Android\android-studio\sdk\platforms\android-19\android.jar -M C:\Users\hvalls\Desktop\my-app\AndroidManifest.xml -S C:\Users\hvalls\Desktop\my-app\res -A C:\Users\hvalls\Desktop\my-app\target\generated-sources\combined-assets\assets -m -J C:\Users\hvalls\Desktop\my-app\target\generated-sources\r --output-text-symbols C:\Users\hvalls\Desktop\my-app\target --auto-add-overlay

因此,当您运行它时,它将为您提供dx.bat工具的实际错误输出。只需修复您在输出中看到的错误,然后重新运行mvn。

在我的情况下,我收到此错误,因为我的res文件夹下的一个图像不是png文件,尽管扩展名为png。我修复了它的文件类型。

答案 1 :(得分:2)

我遇到了同样的错误,花了我2​​.5个工作日来解决问题。 问题实际上是你的文件系统太长了!是的,文件路径太长了!

我从以下项目移动了项目:

C:\工作\工作空间\的IntelliJ \ dory3

C:\工作\ n \鲂

它立刻起作用了。构建时没有错误,IntelliJ没有问题。

答案 2 :(得分:0)

错误消息并没有多说,但这意味着构建你的android apk失败了。如果您查看maven输出高于错误,您可能会看到带有实际错误的消息。在我的情况下它是:

Extracting libs
Generating R file for Planer:AndroidApk:apk:1.0.0
C:\NetBeansProjects\Planer\AndroidApk\res\values\strings.xml:30: error: Resource entry ui.separator is already defined.
C:\NetBeansProjects\Planer\AndroidApk\res\values\strings.xml:29: Originally defined here.

Error when generating sources.
org.apache.maven.plugin.MojoExecutionException: 
    at com.jayway.maven.plugins.android.phase01generatesources.GenerateSourcesMojo.generateR(GenerateSourcesMojo.java:894)
    at com.jayway.maven.plugins.android.phase01generatesources.GenerateSourcesMojo.execute(GenerateSourcesMojo.java:323)
...
Caused by: com.jayway.maven.plugins.android.ExecutionException: ANDROID-040-001: Could not execute: Command ....
...

正如您可以看到有关问题的信息在maven错误上方输入。例如,Mine问题是字符串资源的重复 - 由于某些原因,Android工作室已经复制了。因此,您不必自己运行该命令。看看输出。