本文介绍了无法用Maven构建Android项目(Android的Maven的插件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
奇怪的行为,有时候我可以包我的项目,大部分时间我不能。
在问题发生的android:DEX
:
$ MVN清洁机器人:DEX
[INFO]扫描项目...
[信息]
[INFO] ----------------------------------------------- -------------------------
[INFO]构建测试0.0.1
[INFO] ----------------------------------------------- -------------------------
[信息]
[信息] --- Maven的清理插件:2.3:清理(默认清洁)@测试---
[信息]删除文件集:/家庭/丹尼/工作区/测试/目标(包括:[**],排除:[])
[信息]
[信息] --- Android的Maven的插件:3.3.2:DEX(默认CLI)@测试---
[INFO] /usr/lib/jvm/java-6-sun-1.6.0.26/jre/bin/java [-Xmx1024M,-jar,/home/danny/.bin/android-sdk-linux/platform-tools/ LIB / dx.jar,--dex,--output = /家庭/丹尼/工作区/测试/目标/ classes.dex,/家庭/丹尼/工作区/测试/目标/班]
[信息]
[INFO]意外顶级例外:
[INFO]了java.lang.RuntimeException:/家庭/丹尼/工作区/测试/目标/类:文件未找到
[INFO]在com.android.dx.util.FileUtils.readFile(FileUtils.java:55)
[INFO]在com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:134)
[INFO]在com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
[INFO]在com.android.dx.command.dexer.Main.processOne(Main.java:418)
[INFO]在com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
[INFO]在com.android.dx.command.dexer.Main.run(Main.java:206)
[INFO]在com.android.dx.command.dexer.Main.main(Main.java:174)
[INFO]在com.android.dx.command.Main.main(Main.java:91)
[信息] 1个错误;中止
[INFO] ----------------------------------------------- -------------------------
[INFO]构建失败
[INFO] ----------------------------------------------- -------------------------
[INFO]总时间:1.914s
[INFO]在表面处理:太阳10月7日20点17分03秒CEST 2012
[INFO]最后的内存:7M / 88M
[INFO] ----------------------------------------------- -------------------------
[错误]未能执行目标com.jayway.maven.plugins.android.generation2:Android的Maven的插件:3.3.2:项目测试DEX(默认CLI):MojoExecutionException:ANDROID-040-001:无法执行:命令= / bin / sh的-c CD /家庭/丹尼/工作区/测试和放大器;&安培; /usr/lib/jvm/java-6-sun-1.6.0.26/jre/bin/java -Xmx1024M -jar /home/danny/.bin/android-sdk-linux/platform-tools/lib/dx.jar - -dex --output = /家庭/丹尼/工作区/测试/目标/ classes.dex /家庭/丹尼/工作区/测试/目标/班,结果= 1 - > [求助1]
[错误]
[错误]要查看错误的完整堆栈跟踪,重新运行Maven与-e开关。
[错误]使用-X开关启用完全调试日志记录重新运行Maven。
[错误]
[错误]有关错误和可能的解决方案,请阅读以下文章了解更多信息:
[错误] [说明1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
我找不到这方面的消息?
我的pom.xml:
<项目的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>
<包装和GT;&APK LT; /包装>
<&的artifactId GT;试验< / artifactId的>
<&的groupId GT; com。示例< /的groupId>
<名称>测试与LT; /名称>
<&版GT; 0.0.1< /版本> <依赖和GT;
<&依赖性GT;
<&的artifactId GT; Android和LT; / artifactId的>
<&的groupId GT; com.google.android< /的groupId>
<&范围GT;及提供LT; /&范围GT;
<&版GT; 2.2.1< /版本>
< /依赖性>
<&依赖性GT;
<&的artifactId GT;的JUnit< / artifactId的>
<&的groupId GT;的JUnit< /的groupId>
<&范围GT;试验< /&范围GT;
<&版GT; 4.10 LT; /版本>
< /依赖性>
< /依赖和GT; <建立>
<&插件GT;
<&插件GT;
<&的groupId GT; org.apache.maven.plugins< /的groupId>
<&的artifactId GT; Maven的编译器插件< / artifactId的>
<&版GT; 2.5.1< /版本>
<结构>
<信源> 1.6 LT; /源>
<目标> 1.6 LT; /目标与GT;
< /结构>
< /插件>
<&插件GT;
<&的artifactId GT; Android的Maven的插件< / artifactId的>
<结构>
< assetsDirectory>的src / main /资产< / assetsDirectory>
< resourceDirectory>的src / main /资源< / resourceDirectory>
< SDK开发及GT;
<平台和GT; 8示/平台>
< / SDK>
< /结构>
<附加功能,GT;真< /扩展>
<&的groupId GT; com.jayway.maven.plugins.android.generation2< /的groupId>
<&版GT; 3.3.2< /版本>
< /插件>
< /插件>
< /构建>< /项目>
修改
运行 MVN包
结果:
$ MVN包
[INFO]扫描项目...
[信息]
[INFO] ----------------------------------------------- -------------------------
[INFO]构建测试0.0.1
[INFO] ----------------------------------------------- -------------------------
[信息]
[信息] --- Android的Maven的插件:3.3.2:产生来源(默认生成来源)@测试---
[INFO] ANDROID-904-002:找到AIDL文件:计数= 0
[INFO] ANDROID-904-002:找到AIDL文件:计数= 0
[INFO] /home/danny/.bin/android-sdk-linux/platform-tools/aapt [包,-m,-J /家庭/丹尼/工作区/测试/目标/生成的来源/ R,-M ,/home/danny/workspace/test/AndroidManifest.xml,-S /家庭/丹尼/工作区/测试/ src目录/主/资源,--auto-添加的覆盖,-A,/家庭/丹尼/工作区/测试/ src目录/主/资产,-I,/home/danny/.bin/android-sdk-linux/platforms/android-8/android.jar]
[信息]
[信息] --- Maven的资源 - 插件:2.6:资源(缺省资源)@测试---
【警告】使用平台编码(UTF-8实际上)复制过滤资源,即构建依赖于平台!
[INFO]复制8资源
[信息]跳到不存在的resourceDirectory /家庭/丹尼/工作区/测试/目标/生成的来源/提取依赖性/ src目录/主/资源
[信息]
[信息] --- Maven的编译器插件:2.5.1:编译(默认编译)@测试---
[警告]文件编码尚未设置,使用平台编码UTF-8,即构建依赖于平台!
[INFO] 3编译源文件到/ home /丹尼/工作区/测试/目标/班
[INFO] ----------------------------------------------- --------------
[错误]编译错误:
[INFO] ----------------------------------------------- --------------
[错误] /home/danny/workspace/test/src/main/java/com/example/test/gui/MainActivity.java:[17,18]包R不存在
[错误] /home/danny/workspace/test/src/main/java/com/example/test/gui/MainActivity.java:[26,29]包R不存在
[INFO] 2个错误
[INFO] ----------------------------------------------- --------------
[INFO] ----------------------------------------------- -------------------------
[INFO]构建失败
[INFO] ----------------------------------------------- -------------------------
[INFO]总时间:2.960s
[INFO]在表面处理:太阳10月7日22时40分35秒CEST 2012
[INFO]最后的内存:13M / 86M
[INFO] ----------------------------------------------- -------------------------
[错误]未能执行目标org.apache.maven.plugins:Maven的编译器插件:2.5.1:编译(默认编译)项目的测试:编译失败:编译失败:
[错误] /home/danny/workspace/test/src/main/java/com/example/test/gui/MainActivity.java:[17,18]包R不存在
[错误] /home/danny/workspace/test/src/main/java/com/example/test/gui/MainActivity.java:[26,29]包R不存在
[错误] - > [求助1]
[错误]
[错误]要查看错误的完整堆栈跟踪,重新运行Maven与-e开关。
[错误]使用-X开关启用完全调试日志记录重新运行Maven。
[错误]
[错误]有关错误和可能的解决方案,请阅读以下文章了解更多信息:
[错误] [说明1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
解决方案
生成的研究
文件中使用的包声明 com.example.test
(这是我的项目的groupId),我试图访问它在类 com.example.test.gui.MainActivity
。所以,我需要进口 com.example.test.R
明确。
Strange behavior, sometimes I can package my project, most of the time I cannot.The problem happens in android:dex
:
$ mvn clean android:dex
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Test 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.3:clean (default-clean) @ test ---
[INFO] Deleting file set: /home/danny/workspace/test/target (included: [**], excluded: [])
[INFO]
[INFO] --- android-maven-plugin:3.3.2:dex (default-cli) @ test ---
[INFO] /usr/lib/jvm/java-6-sun-1.6.0.26/jre/bin/java [-Xmx1024M, -jar, /home/danny/.bin/android-sdk-linux/platform-tools/lib/dx.jar, --dex, --output=/home/danny/workspace/test/target/classes.dex, /home/danny/workspace/test/target/classes]
[INFO]
[INFO] UNEXPECTED TOP-LEVEL EXCEPTION:
[INFO] java.lang.RuntimeException: /home/danny/workspace/test/target/classes: file not found
[INFO] at com.android.dx.util.FileUtils.readFile(FileUtils.java:55)
[INFO] at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:134)
[INFO] at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
[INFO] at com.android.dx.command.dexer.Main.processOne(Main.java:418)
[INFO] at com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
[INFO] at com.android.dx.command.dexer.Main.run(Main.java:206)
[INFO] at com.android.dx.command.dexer.Main.main(Main.java:174)
[INFO] at com.android.dx.command.Main.main(Main.java:91)
[INFO] 1 error; aborting
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.914s
[INFO] Finished at: Sun Oct 07 20:17:03 CEST 2012
[INFO] Final Memory: 7M/88M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.3.2:dex (default-cli) on project test: MojoExecutionException: ANDROID-040-001: Could not execute: Command = /bin/sh -c cd /home/danny/workspace/test && /usr/lib/jvm/java-6-sun-1.6.0.26/jre/bin/java -Xmx1024M -jar /home/danny/.bin/android-sdk-linux/platform-tools/lib/dx.jar --dex --output=/home/danny/workspace/test/target/classes.dex /home/danny/workspace/test/target/classes, Result = 1 -> [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
I cannot find any information on this...My 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>
<packaging>apk</packaging>
<artifactId>test</artifactId>
<groupId>com.example</groupId>
<name>Test</name>
<version>0.0.1</version>
<dependencies>
<dependency>
<artifactId>android</artifactId>
<groupId>com.google.android</groupId>
<scope>provided</scope>
<version>2.2.1</version>
</dependency>
<dependency>
<artifactId>junit</artifactId>
<groupId>junit</groupId>
<scope>test</scope>
<version>4.10</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<assetsDirectory>src/main/assets</assetsDirectory>
<resourceDirectory>src/main/resources</resourceDirectory>
<sdk>
<platform>8</platform>
</sdk>
</configuration>
<extensions>true</extensions>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<version>3.3.2</version>
</plugin>
</plugins>
</build>
</project>
EDIT
Running mvn package
results in:
$ mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Test 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- android-maven-plugin:3.3.2:generate-sources (default-generate-sources) @ test ---
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] /home/danny/.bin/android-sdk-linux/platform-tools/aapt [package, -m, -J, /home/danny/workspace/test/target/generated-sources/r, -M, /home/danny/workspace/test/AndroidManifest.xml, -S, /home/danny/workspace/test/src/main/resources, --auto-add-overlay, -A, /home/danny/workspace/test/src/main/assets, -I, /home/danny/.bin/android-sdk-linux/platforms/android-8/android.jar]
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 8 resources
[INFO] skip non existing resourceDirectory /home/danny/workspace/test/target/generated-sources/extracted-dependencies/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ test ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 3 source files to /home/danny/workspace/test/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/danny/workspace/test/src/main/java/com/example/test/gui/MainActivity.java:[17,18] package R does not exist
[ERROR] /home/danny/workspace/test/src/main/java/com/example/test/gui/MainActivity.java:[26,29] package R does not exist
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.960s
[INFO] Finished at: Sun Oct 07 22:40:35 CEST 2012
[INFO] Final Memory: 13M/86M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project test: Compilation failure: Compilation failure:
[ERROR] /home/danny/workspace/test/src/main/java/com/example/test/gui/MainActivity.java:[17,18] package R does not exist
[ERROR] /home/danny/workspace/test/src/main/java/com/example/test/gui/MainActivity.java:[26,29] package R does not exist
[ERROR] -> [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/MojoFailureException
解决方案
The generated R
file used the package declaration com.example.test
(which is the groupId of my project) and I tried to access it in the class com.example.test.gui.MainActivity
. So I needed to import com.example.test.R
explicitly.
这篇关于无法用Maven构建Android项目(Android的Maven的插件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!