2014-03-25 72 views
7

我正在使用Android Studio與Maven 3.1.1,並在包目標與MojoExecutionException崩潰。我收到了很多帖子,但我無法獲得解決方案。MojoExecutionException:與Android的Maven

[錯誤]生成源時出錯。

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> 
+0

解決!我有一個@string \參考一個不存在的string.xml –

回答

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

這是一個很好的建議,但當這是錯誤時它會變得非常複雜:錯誤檢索父項:找不到與給定名稱'主題匹配的資源。 AppCompat.Light.DarkActionBar' –

+0

您是否也可以使用更通用的示例顯示命令,以便更容易理解?我很難理解如何改變這一點,以使它適合我。 –

+0

@PaulGregoire你有這種情況的解決方案嗎? –

2

我有同樣的錯誤,它花了我2.5個工作日來找出問題。 這個問題實際上是在你的文件系統上太長時間了!是的,文件路徑太長!

我感動從項目:

C:\工作\工作區\的IntelliJ \ dory3

C:\工作\ n \魴

,並立即工作。建設時沒有錯誤,IntelliJ沒有問題。

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工作室重複了一次。所以,你不必自己運行這個命令。看看輸出。