我正在尝试使用此处的示例了解Maven Android插件:https://github.com/jayway/maven-android-plugin-samples/archives/stable
我正在使用示例“libraryproject”并且一切正常,只有一件我真的无法弄清楚:如果我将某些内容更改为lib1项目(例如资源文件的内容)并编译主要内容项目,我仍然在生成的apk文件中看到旧资源。
我试图清理,重建,没有改变我的apk ...
抱歉我的英语不好这个愚蠢的问题。
编辑:我只是喜欢yorkw说的话:但现在我收到以下错误:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] Library Projects Parent
[INFO] Library Projects - Library 1
[INFO] Library Projects - Library 2
[INFO] Library Projects - Main App
[INFO] Library Projects - Instrumentation Tests
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Library Projects Parent 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Library Projects - Library 1 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- android-maven-plugin:3.1.1:generate-sources (default-generate-sources) @ libraryprojects-lib1 ---
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] C:\Program Files (x86)\Android\android-sdk-windows\platform-tools\aapt.exe [package, -m, -J, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-lib1\target\generated-sources\r, -M, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-lib1\AndroidManifest.xml, -S, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-lib1\res, --auto-add-overlay, -A, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-lib1\assets, -I, C:\Program Files (x86)\Android\android-sdk-windows\platforms\android-10\android.jar]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Library Projects - Library 2 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- android-maven-plugin:3.1.1:generate-sources (default-generate-sources) @ libraryprojects-lib2 ---
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] C:\Program Files (x86)\Android\android-sdk-windows\platform-tools\aapt.exe [package, -m, -J, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-lib2\target\generated-sources\r, -M, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-lib2\AndroidManifest.xml, -S, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-lib2\res, --auto-add-overlay, -A, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-lib2\assets, -I, C:\Program Files (x86)\Android\android-sdk-windows\platforms\android-10\android.jar]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Library Projects - Main App 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- android-maven-plugin:3.1.1:generate-sources (default-generate-sources) @ libraryprojects-mainapp ---
[DEBUG] Expanding: C:\Users\nicola\.m2\repository\com\jayway\maven\plugins\android\generation2\samples\libraryprojects\libraryprojects-lib1\1.0.0-SNAPSHOT\libraryprojects-lib1-1.0.0-SNAPSHOT.apklib into C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\target\unpack\apklibs\com.jayway.maven.plugins.android.generation2.samples.libraryprojects_libraryprojects-lib1_apklib_1.0.0-SNAPSHOT
[DEBUG] expand complete
[DEBUG] Expanding: C:\Users\nicola\.m2\repository\com\jayway\maven\plugins\android\generation2\samples\libraryprojects\libraryprojects-lib2\1.0.0-SNAPSHOT\libraryprojects-lib2-1.0.0-SNAPSHOT.apklib into C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\target\unpack\apklibs\com.jayway.maven.plugins.android.generation2.samples.libraryprojects_libraryprojects-lib2_apklib_1.0.0-SNAPSHOT
[DEBUG] expand complete
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] C:\Program Files (x86)\Android\android-sdk-windows\platform-tools\aapt.exe [package, -m, -J, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\target\generated-sources\r, -M, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\AndroidManifest.xml, -S, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\res, -S, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\target\unpack\apklibs/com.jayway.maven.plugins.android.generation2.samples.libraryprojects_libraryprojects-lib1_apklib_1.0.0-SNAPSHOT/res, -S, C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\target\unpack\apklibs/com.jayway.maven.plugins.android.generation2.samples.libraryprojects_libraryprojects-lib2_apklib_1.0.0-SNAPSHOT/res, --auto-add-overlay, -I, C:\Program Files (x86)\Android\android-sdk-windows\platforms\android-10\android.jar]
[INFO] C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\res\layout\main.xml:12: error: Error: No resource found that matches the given name (at 'text' with value '@string/lib1resource').
[INFO] C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\res\layout\main.xml:17: error: Error: No resource found that matches the given name (at 'text' with value '@string/lib2resource').
[ERROR] Error when generating sources.
org.apache.maven.plugin.MojoExecutionException:
at com.jayway.maven.plugins.android.phase01generatesources.GenerateSourcesMojo.generateR(GenerateSourcesMojo.java:338)
at com.jayway.maven.plugins.android.phase01generatesources.GenerateSourcesMojo.execute(GenerateSourcesMojo.java:102)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
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:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: com.jayway.maven.plugins.android.ExecutionException: ANDROID-040-001: Could not execute: Command = cmd.exe /X /C ""C:\Program Files (x86)\Android\android-sdk-windows\platform-tools\aapt.exe" package -m -J C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\target\generated-sources\r -M C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\AndroidManifest.xml -S C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\res -S C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\target\unpack\apklibs/com.jayway.maven.plugins.android.generation2.samples.libraryprojects_libraryprojects-lib1_apklib_1.0.0-SNAPSHOT/res -S C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\target\unpack\apklibs/com.jayway.maven.plugins.android.generation2.samples.libraryprojects_libraryprojects-lib2_apklib_1.0.0-SNAPSHOT/res --auto-add-overlay -I "C:\Program Files (x86)\Android\android-sdk-windows\platforms\android-10\android.jar"", Result = 1
at com.jayway.maven.plugins.android.CommandExecutor$Factory$1.executeCommand(CommandExecutor.java:215)
at com.jayway.maven.plugins.android.phase01generatesources.GenerateSourcesMojo.generateR(GenerateSourcesMojo.java:336)
... 22 more
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Library Projects Parent ........................... SUCCESS [0.004s]
[INFO] Library Projects - Library 1 ...................... SUCCESS [1.109s]
[INFO] Library Projects - Library 2 ...................... SUCCESS [0.299s]
[INFO] Library Projects - Main App ....................... FAILURE [0.489s]
[INFO] Library Projects - Instrumentation Tests .......... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.277s
[INFO] Finished at: Wed Apr 18 02:46:34 CEST 2012
[INFO] Final Memory: 5M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.1.1:generate-sources (default-generate-sources) on project libraryprojects-mainapp: MojoExecutionException: ANDROID-040-001: Could not execute: Command = cmd.exe /X /C ""C:\Program Files (x86)\Android\android-sdk-windows\platform-tools\aapt.exe" package -m -J C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\target\generated-sources\r -M C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\AndroidManifest.xml -S C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\res -S C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\target\unpack\apklibs/com.jayway.maven.plugins.android.generation2.samples.libraryprojects_libraryprojects-lib1_apklib_1.0.0-SNAPSHOT/res -S C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\target\unpack\apklibs/com.jayway.maven.plugins.android.generation2.samples.libraryprojects_libraryprojects-lib2_apklib_1.0.0-SNAPSHOT/res --auto-add-overlay -I "C:\Program Files (x86)\Android\android-sdk-windows\platforms\android-10\android.jar"", 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
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :libraryprojects-mainapp
答案 0 :(得分:3)
您应该在父项目文件夹(../libraryprojects)中构建项目(mvn clean install),这将构建libraryprojects-lib1项目(以便将最新的apklib安装到您的本地maven存储库中)以及libraryprojects-mainapp项目
如果在子项目文件夹(../libraryprojects/libraryprojects-mainapp)中构建项目(mvn clean install),这将只构建libraryprojects-mainapp并使用存储在本地maven存储库中的现有apklib进行项目依赖。换句话说,libraryprojects-lib1项目重建没有发生,并且有助于libraryprojects-mainapp项目的构建生命周期。
请注意,如果您在Eclipse中导入整个项目并通过Eclipse清理/构建libraryprojects-mainapp,它将自动触发依赖库项目libraryprojects-lib1的重建过程。
<强>更新强>
我已经下载了最新的android maven插件并尝试在我的Windows XP盒子上复制问题,它实际上是一个Microsoft Fault!如果您尝试访问(这是构建项目时创建的临时文件夹Maven之一):
C:\Users\nicola\Desktop\maven_example\jayway-maven-android-plugin-samples-c475bf4\libraryprojects\libraryprojects-mainapp\target\unpack\apklibs\com.jayway.maven.plugins.android.generation2.samples.libraryprojects_libraryprojects-lib2_apklib_1.0.0-SNAPSHOT\res
从资源管理器中获取:
查看here和here了解详情。 Windows上的最大路径长度限制为256个字符。
解决方案:
首先,尝试使用短路径,例如,可以找到以下内容:
C:\c475bf4\libraryprojects\libraryprojects-mainapp\target\unpack\apklibs\com.jayway.maven.plugins.android.generation2.samples.libraryprojects_libraryprojects-lib2_apklib_1.0.0-SNAPSHOT\res
然后再试一次,看看你是否可以构建它,你可能会得到另一个构建错误(我试过我的Windows XP框并得到此错误),如下所示:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.1:compile (default-compile) on project libraryprojects-mainapp: Compilation failure: Compilation failure:
[ERROR] C:\c475bf4\libraryprojects\libraryprojects-mainapp\src\main\java\com\jayway\maven\plugins\android\generation2\samples\libraryprojects\mainapp\MainActivity.java:[16,5] annotations are not supported in -source 1.3
要解决此问题,您可以在.. \ libraryprojects \ pom.xml中指定更高版本的maven-compiler-plugin:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
最后但并非最不重要的是,请注意您需要打开模拟器才能让测试子项目运行检测测试,否则构建测试项目将失败。
希望这有帮助。
答案 1 :(得分:1)
我遇到了同样的问题,解决方法是使用Eclipse Marketplace更新/安装Maven android配置程序。 (Eclipse帮助 - &gt; Eclipse市场 - &gt;找到maven android配置器并安装它)
之前我还使用Eclipse帮助更新了m2e插件 - &gt;检查更新
如果没有帮助,请尝试逐步搜索错误。我已经描述了使用android和eclipse here
配置maven所需的所有步骤