1

我正在尝试通过此处找到的示例来了解 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
4

2 回答 2

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 机器上试一试并复制了问题,这实际上是微软的错误!如果您尝试访问(这是构建项目时创建的临时文件夹 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

从资源管理器,你得到: 在此处输入图像描述

查看此处此处了解更多详细信息。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>

最后但同样重要的是,请注意,您需要打开一个模拟器才能让测试子项目运行仪器测试,否则构建测试项目将失败。

希望这可以帮助。

于 2012-04-18T00:32:24.167 回答
1

我遇到了同样的问题,解决方案是使用 Eclipse Marketplace 更新/安装 Maven android 配置器。(Eclipse 帮助 -> Eclipse 市场 -> 找到 maven android 配置器并安装它)

早些时候我还使用 Eclipse 帮助更新了 m2e 插件 -> 检查更新

如果没有帮助,请尝试逐步搜索错误。我在这里描述了使用 android 和 eclipse 配置 maven 所需的所有步骤

于 2012-09-29T10:48:21.600 回答